numpy之reshape函数

numpy中reshape函数

以下为代码展示:

>>> import numpy as np
>>> 
>>> a = np.ones([2,3,4,5])
>>> a.shape
(2, 3, 4, 5)
>>> 
>>> b=np.reshape(a,[-1])
>>> b.shape
(120,)
>>> 
>>> b=np.reshape(a,[-1,1])
>>> b.shape
(120, 1)
>>> b=np.reshape(a,[2,60])
>>> b.shape
(2, 60)
>>> 
>>> b=np.reshape(a,[-1,1])
>>> b.shape
(120, 1)
>>> 

由以上不难看出,reshape()函数中参数 -1 代表array(含有n个元素)的reshape之后在该维度上的最大值x;使用数学表达式:

n = x * a * b * c * … *d, a b c 分别为reshape成其他维度上的元素数量

猜你喜欢

转载自blog.csdn.net/yangwangnndd/article/details/89419506