Reputation: 4046
Say I have a 2 x 8 x 3 array, like so:
array([[[ 0, 1, 2],
[ 1, 2, 3],
[ 2, 3, 4],
[ 3, 4, 5],
[ 4, 5, 6],
[ 5, 6, 7],
[ 6, 7, 8],
[ 7, 8, 9]],
[[10, 11, 12],
[11, 12, 13],
[12, 13, 14],
[13, 14, 15],
[14, 15, 16],
[15, 16, 17],
[16, 17, 18],
[17, 18, 19]]])
How do I reshape it so that it becomes an 8 x 2 x 3 array with elements like
[[[ 0, 1, 2],
[10, 11, 12]],
[[ 1, 2, 3],
[11, 12, 13]],
...
reshape(8, 2, 3)
gives the following result, which is not what I want:
array([[[ 0, 1, 2],
[ 1, 2, 3]],
[[ 2, 3, 4],
[ 3, 4, 5]],
[[ 4, 5, 6],
[ 5, 6, 7]],
[[ 6, 7, 8],
[ 7, 8, 9]],
[[10, 11, 12],
[11, 12, 13]],
[[12, 13, 14],
[13, 14, 15]],
[[14, 15, 16],
[15, 16, 17]],
[[16, 17, 18],
[17, 18, 19]]])
If it works for a general second dimension (not just m=2), even better. Thank you!
Upvotes: 0
Views: 78