I do have a 3D np.array like this:
arr3d = np.arange(36).reshape(3, 2, 6)
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]],
[[24, 25, 26, 27, 28, 29],
[30, 31, 32, 33, 34, 35]]])
I need to horizontally split every pane of arr3d into 3 chunks, such as:
np.array(np.hsplit(arr3d[0, :, :], 3))
array([[[ 0, 1],
[ 6, 7]],
[[ 2, 3],
[ 8, 9]],
[[ 4, 5],
[10, 11]]])
This should then lead to a 4D array.
arr4d[0, :, :, :] should contain the new splitted 3D array of the first pane of the original 3D array (np.array(np.hsplit(arr3d[0, :, :], 3)))
The final result should look like this:
result = np.array(
[
[[[0, 1], [6, 7]], [[2, 3], [8, 9]], [[4, 5], [10, 11]]],
[[[12, 13], [18, 19]], [[14, 15], [20, 21]], [[16, 17], [22, 23]]],
[[[24, 25], [30, 31]], [[26, 27], [32, 33]], [[28, 29], [34, 35]]],
]
)
result.shape
(3, 3, 2, 2)
array([[[[ 0, 1],
[ 6, 7]],
[[ 2, 3],
[ 8, 9]],
[[ 4, 5],
[10, 11]]],
[[[12, 13],
[18, 19]],
[[14, 15],
[20, 21]],
[[16, 17],
[22, 23]]],
[[[24, 25],
[30, 31]],
[[26, 27],
[32, 33]],
[[28, 29],
[34, 35]]]])
I am looking for a pythonic way to perform this reshaping/splitting.