np.where(condition) 当where内只有一个参数时,那个参数表示条件,当条件成立时,where返回的是每个符合condition条件元素的坐标,返回的是以元组(内部为np数组)的形式
import numpy as np
a = np.array([[2,4,6,8,10],
[2,4,7,6,10],
[7,4,6,6,10]])
b=np.where(a > 6)
c=b[1] #取列索引
print(b)
print(type(b))
print(c)
print(type(c))
print(list(c))
print(a[:, c])
输出为
(array([0, 0, 1, 1, 2, 2]), array([3, 4, 2, 4, 0, 4]))
<class 'tuple'>
[3 4 2 4 0 4]
<class 'numpy.ndarray'>
[3, 4, 2, 4, 0, 4]
[[ 8 10 6 10 2 10]
[ 6 10 7 10 2 10]
[ 6 10 6 10 7 10]]