How do you reduce the dimension of a numpy array?

前端 未结 2 1104
甜味超标
甜味超标 2021-01-13 02:38

I started with an mxnxp array, A,

In [16]: A
Out[16]: 
array([[[  2.10000000e+01,   3.70060693e-01],
        [  2.00000000e+01,   2         


        
2条回答
  •  甜味超标
    2021-01-13 02:53

    You could use numpy.squeeze()

    x = np.array([[[0], [1], [2]]])
    x.shape
    (1, 3, 1)
    np.squeeze(x).shape
    (3,)
    np.squeeze(x, axis=(2,)).shape
    (1, 3)
    

提交回复
热议问题