如何在numpy中创建3维矩阵,如matlab a(:,:,:) [英] How to create 3 dimensions matrix in numpy , like matlab a(:,:,:)
问题描述
如何在numpy中创建3维矩阵,例如matlab a(:,:,:).我尝试通过使用numpy.array将可创建3d矩阵的matlab代码转换为python,但我不知道如何在numpy中创建3d矩阵/数组
How to create 3 dimensions matrix in numpy , like matlab a(:,:,:) . I try to convert matlab code that create 3d matrix to python by use numpy.array and i don't know how to create 3d matrix/array in numpy
推荐答案
a=np.empty((2,3,5))
创建一个2x3x5数组. (如果要初始化值,则还有np.zeros.)
creates a 2x3x5 array. (There is also np.zeros if you want the values initialized.)
您还可以调整现有数组的形状:
You can also reshape existing arrays:
a=np.arange(30).reshape(2,3,5)
np.arange(30)创建一个1-d数组,其值从0..29开始. reshape()方法返回一个数组,其中包含具有相同形状的相同数据.
np.arange(30) creates a 1-d array with values from 0..29. The reshape() method returns an array containing the same data with a new shape.
这篇关于如何在numpy中创建3维矩阵,如matlab a(:,:,:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!