Reputation: 71
I want to create a 2x2x3 three-dimensional array in Python.
I did the following:
x = numpy.array([[[1,1], [2,2], [3,3]], [[1,1], [1,1], [1,1]]])
However, my output is a 2x3x2 array.
print(x.shape)
What did I wrong? And can anyone please explain step by step how to build a 3D array, I am a bit confused about the rows, colums and axis.
Thank you in advance.
Upvotes: 0
Views: 11701
Reputation: 1318
This might be what you want
x = np.array([[[1,1,2], [2,3,3]], [[1,1,1], [1,1,1]]])
print(x.shape)
print(x)
Refer to this documentation for explanation.
What you created was an array with 3 rows, 2 columns and say 2 frames so you didn't get what you wanted (2 rows & 3 columns). We can make a 3d array representation as (frames, rows, columns)
.
Further you could've created an array with dimensions (n,)
using
x = np.array([1, 1, 2, 2, 3, 3, 1, 1, 1, 1, 1, 1])
Then you can reshape it as per the requirement
For 2x2x3
you could do
x = x.reshape(2,2,3)
Similarly for 2x3x2
x = x.reshape(2,3,2)
Upvotes: 3