Split A 3d Numpy Array Into Smaller 3d Arrays
I have a 3D np.array arr = np.array([ [ [0, 205, 25], [210, 150, 30], [0, 0, 0], [1, 2, 3], [4, 5, 6], [7, 8, 9] ], [ [0, 255, 0], [255, 40, 0], [0
Solution 1:
You can reshape and transpose it
arr.reshape(3, 3, 3, 2, 3).transpose(2, 0, 1, 3, 4)
# array([[[[[ 0, 205, 25],
# [210, 150, 30]],
#
# [[ 0, 255, 0],
# [255, 40, 0]],
#
# [[ 0, 0, 30],
# [ 0, 40, 0]]],
#
#
# [[[ 0, 205, 25],
# [210, 150, 30]],
#
# [[ 0, 255, 0],
# [255, 40, 0]],
#
# [[ 0, 0, 30],
# [ 0, 40, 0]]],
#
#
# ...
Post a Comment for "Split A 3d Numpy Array Into Smaller 3d Arrays"