时间:2020-10-08 13:28:52 | 栏目:Python代码 | 点击:次
如下所示:
>>> import numpy as np >>> a = np.arange(12).reshape(3,4) >>> a array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> type(a) <class 'numpy.ndarray'> >>> b=np.reshape(a,(3,4,1)) >>> np.shape(b) (3, 4, 1) >>> c=np.concatenate([b,b],2) >>> np.shape(c) (3, 4, 2)
对于 numpy.ndarry格式的变量才行,常量不可以。
>>> b=np.mat([0,0,0]) >>> c=np.tile(b,(2,1)) >>> np.shape(c) (2, 3) >>> type(c) <class 'numpy.matrixlib.defmatrix.matrix'> >>> d=np.reshape(c,(2,3,1)) >>> np.shape(d)