看来您正在将第三个轴从 (4) 分解为 (2,2) 并将分割轴的前半部分带到倒数第二个轴位置。因此,有两种方法可以实现这样的输出:np.reshape http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.reshape.html and np.transpose http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.transpose.html,就像这样-
out = a.reshape(2,2,2,2,2,2).transpose(0,1,3,4,2,5).reshape(2,2,4,4)
out = a.reshape(2,2,2,-1,2).transpose(0,1,3,2,4).reshape(2,2,4,4)
样本运行 -
In [69]: a[0][0]
Out[69]:
array([[[49, 91],
[10, 32]],
[[71, 27],
[50, 64]],
[[ 9, 41],
[73, 52]],
[[54, 85],
[53, 36]]])
In [70]: out1 = a.reshape(2,2,2,2,2,2).transpose(0,1,3,4,2,5).reshape(2,2,4,4)
In [71]: out2 = a.reshape(2,2,2,-1,2).transpose(0,1,3,2,4).reshape(2,2,4,4)
In [72]: out1[0][0]
Out[72]:
array([[49, 91, 9, 41],
[10, 32, 73, 52],
[71, 27, 54, 85],
[50, 64, 53, 36]])
In [73]: out2[0][0]
Out[73]:
array([[49, 91, 9, 41],
[10, 32, 73, 52],
[71, 27, 54, 85],
[50, 64, 53, 36]])