How to create 3 dimensions matrix in numpy , like matlab a(:,:,:)

后端 未结 1 1243
傲寒
傲寒 2021-02-01 17:10

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 crea

相关标签:
1条回答
  • 2021-02-01 17:56
    a=np.empty((2,3,5))
    

    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) creates a 1-d array with values from 0..29. The reshape() method returns an array containing the same data with a new shape.

    0 讨论(0)
提交回复
热议问题