【python】numpy.newaxis的使用

作用

        np.newaxis的作用是帮助数组创建新轴,或者也叫增加维度。np.newaxis 在使用和功能上等价于 None,其实就是 None 的一个别名。

a= np.array([x for x in range(5)])
print(a)
print(a.shape)

[0 1 2 3 4]
(5,)
b = a[np.newaxis,:]
print(b)
print(b.shape)

[[0 1 2 3 4]]
(1, 5)
c = a[:,np.newaxis]
print(c)
print(c.shape)

[[0]
 [1]
 [2]
 [3]
 [4]]
(5, 1)

猜你喜欢

转载自blog.csdn.net/qq_20135597/article/details/83310336