1.单条件查找
矩阵A大小为m×n,
利用numpy.where可以对A进行数据筛选,比如获取A矩阵中元素大于5的所有数值
import numpy as np
A = np.array([[2, 20],[24, 40],[32, 28]])
B = np.argwhere(A>5) #大于5所有元素的索引
print(B)
输出符合条件的元素位置,结果为:
[[0 1]
[1 0]
[1 1]
[2 0]
[2 1]]
2.多条件查找
筛选第一列大于5,第二列小于30的行
B = np.argwhere( (A[:,0:1]>5) & (A[:,1:2]<30) )
print(B)
输出符合条件的元素位置,即第二行,结果为:
[[2 0]]