b=a[np.newaxis,:]的功能解释

下面以例子来说明
import numpy as np
a=np.array([1,2,3,4,5])
b=a[np.newaxis,:]
print (a.shape,b.shape)
print (a)
print (b)
c=a[:np.newaxis]
print(c.shape)
print©
结果如下:
(5,) (1, 5)
[1 2 3 4 5]
[[1 2 3 4 5]]
(5,)
[1 2 3 4 5]
大概应该就明白了,np.newaxis,就是增加一个维度,比如说将(5,) 变成(1, 5),只需要在行维度上写上np.newaxis即可,应该能够理解了吧,我是这么理解的哈哈。

猜你喜欢

转载自blog.csdn.net/weixin_43213268/article/details/88786106