首页 > 开发 > Python > 正文

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

2020-07-28 13:57:59
字体:
来源:转载
供稿:网友

如下所示:

>>> import numpy as np>>> a = np.arange(12).reshape(3,4)>>> aarray([[ 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)

以上这篇python 二维矩阵转三维矩阵示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持错新网之家。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表