What's the best way to create 2D arrays in Python?
What I want is want is to store values like this:
X , Y , Z
so that I access data like X[2],Y[2],Z[2] or X[n],Y[n],Z[n] where n is variable.
I don't know in the beginning how big n would be so I would...

Asked By spring liu

Does anybody know how to extract a column from a multi-dimensional array in Python?

Asked By jaweria

There are literally thousands of these posts but I haven't seen one yet that addresses my exact problem. Please feel free to close this if one exists.
I understand that lists are mutable in Python. As a result, we cannot store a list as a key in a dictio...

Asked By user6467981

I want to know how to declare a two dimensional array in Python.
arr = [[]]
arr[0].append("aa1")
arr[0].append("aa2")
arr[1].append("bb1")
arr[1].append("bb2")
arr[1].append("bb3")
The first two assignments work fine. But when I try to do, arr[1].appe...

Asked By SyncMaster

I wonder whether there is a shortcut to make a simple list out of list of lists in Python.
I can do that in a for loop, but maybe there is some cool "one-liner"? I tried it with reduce, but I get an error.
Code
l = [[1, 2, 3], [4, 5, 6], [7], [8, 9]]
r...

Asked By Emma

I am trying to animate a pcolormesh in matplotlib. I have seen many of the examples using the package animation, most of them using a 1D plot routine, and some of them with imshow().
First, I wan to use the FuncAnimation routine. My problem is, first, tha...

Asked By AlexNoir

In Tensorflow, I want to save a multidimensional array to a TFRecord. For example:
[[1, 2, 3], [1, 2], [3, 2, 1]]
As the task I am trying to solve is sequential, I am trying to use Tensorflow's tf.train.SequenceExample() and when writing the data I am ...

Asked By Torkoal

I want to convert a 1-dimensional array into a 2-dimensional array by specifying the number of columns in the 2D array. Something that would work like this:
> import numpy as np
> A = np.array([1,2,3,4,5,6])
> B = vec2matrix(A,ncol=2)
> B
arr...

Asked By Alex Williams

I have created a 2 dimension array like:
rows =3
columns= 2
mylist = [[0 for x in range(columns)] for x in range(rows)]
for i in range(rows):
for j in range(columns):
mylist[i][j] = '%s,%s'%(i,j)
print mylist
Printing this list gives an out...

Asked By bhaskarc

I am trying to create a matrix transpose function for python but I can't seem to make it work.
Say I have
theArray = [['a','b','c'],['d','e','f'],['g','h','i']]
and I want my function to come up with
newArray = [['a','d','g'],['b','e','h'],['c', 'f',...

Asked By Julio Diaz

I'm beginning python and I'm trying to use a two-dimensional list, that I initially fill up with the same variable in every place. I came up with this:
def initialize_twodlist(foo):
twod_list = []
new = []
for i in range (0, 10):
for ...

Asked By thepandaatemyface

I decoded a JPEG image and have it in the shape n_samples x n_features as a two-dimensional numpy.ndarray. I feed this to tensorflow as following:
sess.run(train_step, feed_dict={X : train_set.Features, y_ : train_set.labels})
This returns a TypeError...

Asked By PeterHeuz

In MATLAB there is an easy way to define multidimensional arrays e.g.
A(:,:,1) = [1,2,3; 4,5,6];
A(:,:,2) = [7,8,9; 10,11,12];
>> A
A(:,:,1) =
1 2 3
4 5 6
A(:,:,2) =
7 8 9
10 11 12
where the first two in...

Asked By S88S

I would like to create a 3D array in Python (2.7) to use like this:
distance[i][j][k]
And the sizes of the array should be the size of a variable I have. (n*n*n)
I tried using:
distance = [[[]*n]*n]
but that didn't seem to work.
Any ideas? Thanks ...

Asked By Laís Minchillo

In Python, I have an ndarray y
that is printed as array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
I'm trying to count how many 0s and how many 1s are there in this array.
But when I type y.count(0) or y.count(1), it says
numpy.ndarray object has no at...

Asked By mflowww

I am learning tensorflow, I picked up the following code from the tensorflow website. According to my understanding, axis=0 is for rows and axis=1 is for columns.
How are they getting output mentioned in comments? I have mentioned output according to my ...

Asked By Bhaskar Dhariyal

I am learning tensorflow, I picked up the following code from the tensorflow website. According to my understanding, axis=0 is for rows and axis=1 is for columns.
How are they getting output mentioned in comments? I have mentioned output according to my ...

Asked By Bhaskar Dhariyal