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)

猜你喜欢

转载自blog.csdn.net/cu_is_me/article/details/82989633