split
不能同时与多个轴一起使用。但这里有一个使用此操作两次的解决方案:
In [1]: import numpy as np
In [2]: data = np.arange(24).reshape(4,6)
In [3]: chunk = 2, 2
In [4]: tmp = np.array(np.split(data, data.shape[1]/chunk[1], axis=1))
In [5]: answer = np.vstack(np.split(tmp, tmp.shape[1]/chunk[0], axis=1))
In [6]: answer
Out[6]:
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]]])
不过我更喜欢块状 https://stackoverflow.com/questions/16856788/slice-2d-array-into-smaller-2d-arraysCyber 注意到的解决方案。