reshape - juedaiyuer/researchNote GitHub Wiki

#numpy函数:reshape#

通过reshape生成的新数组和原始数组公用一个内存

创建一个一维数组a

>>> a=np.array([1,2,3,4,5,6,7,8])
>>> a
array([1, 2, 3, 4, 5, 6, 7, 8])

使用reshape()方法更改数组的形状

>>> d=a.reshape((2,4))
>>> d
array([[1, 2, 3, 4],
	   [5, 6, 7, 8]])

可以得到一个三维数组

>>> f=a.reshape((2,2,2))
>>> f
array([[[1, 2],
	    [3, 4]],

	   [[5, 6],
	    [7, 8]]])