I have a NumPy array as follows:
arr = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]])
I am looking to arrange such that it looks like this:
[[[6,7,8,9,10],
[1,2,3,4,5]],
[[11,12,13,14,15],
[6,7,8,9,10]],
[[16,17,18,19,20],
[11,12,13,14,15]]]
So essentially a 3D array with 2x5 in each row of the array. The code I tried is:
x=np.zeros([3,2,5])
for i in range(len(arr)):
x[i]=arr[i:i+2,:][::-1]
But this results in the below output:
[[[ 6. 7. 8. 9. 10.]
[ 1. 2. 3. 4. 5.]]
[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]
[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]]
[[[ 6. 7. 8. 9. 10.]
[ 1. 2. 3. 4. 5.]]
[[11. 12. 13. 14. 15.]
[ 6. 7. 8. 9. 10.]]
[[ 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.]]]
[[[ 6. 7. 8. 9. 10.]
[ 1. 2. 3. 4. 5.]]
[[11. 12. 13. 14. 15.]
[ 6. 7. 8. 9. 10.]]
[[16. 17. 18. 19. 20.]
[11. 12. 13. 14. 15.]]]