np.where(A ==2)[0]
给出的索引 A 其中元素等于2。
A
你如何归纳出一系列可能的值?
我正在寻找类似以下内容:
np.where(A in ([2,3,6,8]))[0]
自从 NumPy 1.13 您可以使用 isin 作用
isin
在以前的版本中 in1d .
in1d
A = np.array([1, 2, 3, 4, 5]) print(np.isin(A, [2, 3, 6, 8]))
[False True True False False]