【问题标题】:How to create 3 dimensions matrix in numpy , like matlab a(:,:,:)如何在 numpy 中创建 3 维矩阵,如 matlab a(:,:,:)
【发布时间】:2009-11-08 11:47:19
【问题描述】:

如何在 numpy 中创建 3 维矩阵,如 matlab a(:,:,:) 。我尝试使用 numpy.array 将创建 3d 矩阵的 matlab 代码转换为 python,但我不知道如何在 numpy 中创建 3d 矩阵/数组

【问题讨论】:

    标签: python matlab numpy


    【解决方案1】:
    a=np.empty((2,3,5))
    

    创建一个 2x3x5 数组。 (如果要初始化值,还有 np.zeros 。)

    您还可以重塑现有数组:

    a=np.arange(30).reshape(2,3,5)
    

    np.arange(30) 创建一个一维数组,其值从 0..29 开始。 reshape() 方法返回一个数组,其中包含具有新形状的相同数据。

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-06
      • 2018-08-10
      • 2014-06-21
      • 2021-12-12
      相关资源
      最近更新 更多