网络编程
位置:首页>> 网络编程>> Python编程>> python 二维矩阵转三维矩阵示例

python 二维矩阵转三维矩阵示例

作者:cu_is_me  发布时间:2023-09-14 03:53:56 

标签: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)

来源:https://blog.csdn.net/cu_is_me/article/details/82989633

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com