How to make a 2d numpy array a 3d array?

后端 未结 8 1684
小鲜肉
小鲜肉 2020-12-08 02:24

I have a 2d array with shape (x, y) which I want to convert to a 3d array with shape (x, y, 1). Is there a nice Pythonic way to do this?

8条回答
  •  攒了一身酷
    2020-12-08 03:18

    You can do this with reshape

    For example, you have an array A of shape 35 x 750 (two dimensions), you can change the shape to 35 x 25 x 30 (three dimensions) with A.reshape(35, 25, 30)

    More in the documentation here

提交回复
热议问题