numpy.ma.MaskedArray.reshape详解
2019年1月24日[MathematicaIn]   reshape.arange(24).reshape(2,3,4) 
[MathematicaOut]  
[[[0,1,2,3], [4,5,6,7], [8,9,10,11]], [[12,13,14,15], [16,17,18,19], [20,21,22,23]]]
reshape的维度之积必须与原数组长度相同。
[MathematicaIn]   reshape.arange(20).reshape(2,3,4) 
[MathematicaOut]  ValueError: cannot reshape array of size 20 into shape (2,3,5) 
[MathematicaIn]   reshape.arange([[1,2,3],
 [4,5,6],
 [7,8,9]]).reshape(2,3,4) 
[MathematicaOut]  ValueError: cannot reshape array of size 9 into shape (2,3,5) 
性质:若运行reshape(a,b,c,d),设返回的矩阵为m,则m[0,0,:,:]有c*d个元素。
例题1:
m=np.arange(240).reshape(4,5,6,2),求m[1,2,3,0]。
解:
m[0,:,:,:]有5*6*2=60个元素。
m[1,0,:,:]从60起,并有6*2=12个元素。
m[1,1,:,:]从72起。
m[1,2,:,:]从84起。
m[1,2,:,:]= [[84,85],
 [86,87],
 [88,89],
 [90,91],
 [92,93],
 [94,95]]
倒数第2个索引是纵向的,最后一个索引是横向的,所以m[1,2,3,0]=90。
例题2:
m=np.arange(32760).reshape(12,13,14,15),求m[9,8,7,6]。
解:
m[0,:,:,:].size=13*14*15=2730。
m[9,0,:,:]从2730*9=24570起,且有14*15=210个元素。
m[9,8,0,:]从24570+210*8=26250起,且有15个元素。
m[9,8,7,0]从26250+15*7=26355起,且有1个元素。
m[9,8,7,6]=26355+1*6=26361.