Reputation: 24661
For example, if:
a = numpy.array([[[[1,2],[3,4]],[[5,6],[7,8]]],[[[11,12],[13,14]],[[15,16],[17,18]]]])
then I would like to eventually obtain:
1 2 5 6
3 4 7 8
11 12 15 16
13 14 17 18
Simple reshaping won't work unfortunately.
Upvotes: 2
Views: 81
Reputation: 177088
You need to swap the second and third axes first, and then reshape:
>>> a.swapaxes(1, 2).reshape(4, 4)
array([[ 1, 2, 5, 6],
[ 3, 4, 7, 8],
[11, 12, 15, 16],
[13, 14, 17, 18]])
Upvotes: 4