Reputation: 143
I have (808,1,22,2000) list array which load from json file.
It has 808 number of (22,2000) arrays.
so i want to make this to (22,2000,808).
Can you let me know how to do it?
Upvotes: 0
Views: 6425
Reputation: 850
Although there is an ambiguity here because it's not clear why you want to change the shape, if I'm right, numpy.reshape
should be your answer.
Look at this example:
>> a = np.array([[[[0,1,2,3],[4,5,6,7]]],[[[8,9,10,11],[12,13,14,15]]],[[[16,17,18,19],[20,21,22,23]]]])
>> a
array([[[[ 0, 1, 2, 3],
[ 4, 5, 6, 7]]],
[[[ 8, 9, 10, 11],
[12, 13, 14, 15]]],
[[[16, 17, 18, 19],
[20, 21, 22, 23]]]])
>> a.shape
(3, 1, 2, 4)
>> b = a.reshape((a.shape[2],a.shape[3],a.shape[0]))
>> b
array([[[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]],
[[12, 13, 14],
[15, 16, 17],
[18, 19, 20],
[21, 22, 23]]])
>> b.shape
(2, 4, 3)
Upvotes: 4