Python讲堂 np.newaxis 为 numpy.ndarray(多维数组)增加一个轴

https://blog.csdn.net/lanchunhui/article/details/49725065

>>> import numpy as np
>>> b = np.array(a)
>>> print(b)
[[1 2 3 4]
 [1 2 3 4]
 [1 2 3 4]]

>>> c=b[:,0]
>>> print(c)
[1 1 1]
>>> np.maximum(2,c)
array([2, 2, 2])

>>> np.maximum(2,c)[:,np.newaxis]
array([[2],
       [2],
       [2]])

>>> d=np.maximum(2,c)[:,np.newaxis]
>>> print(d)
[[2]
 [2]
 [2]]

>>> d[2]
array([2])

>>> e=np.maximum(2,c)
>>> print(e)
[2 2 2]

>>> e[2]
2

 

 

猜你喜欢

转载自blog.csdn.net/zjc910997316/article/details/85255399