Let's say I had a numpy array like this:
[[[ 1, 2, 3, 4],
[ 5, 6, 7, 8],
[ 9, 10, 11, 12],
[13, 14, 15, 16]]]
Which has the dimensions of (1, 4, 4)
and I wanted to convert it to:
[[[[ 1, 3], [ 2, 4]],
[[ 5, 7], [ 6, 8]],
[[ 9, 11], [10, 12]],
[[13, 15], [14, 16]]]]
Which has the dimensions of (1, 4, 2, 2).
Is there any function within numpy which I could use to modify the array as such?
- array.reshape() is close, but not entirely because it cannot swap items.
I want to avoid using straight python as this code is being used to format some data for a neural network input, and the speed of python (given the size of the actual arrays are) is likely to be a bottleneck.