numpy-isin-筛选所有在范围内的

可以进行逐个元素的判断,判断这些东西有没有在给定的数组中。

1
2
3
4
5
6
>>> np.isin(np.array([1,2,3]), [1,2])
array([ True, True, False])
>>> np.array([1,2,3]) in [1,2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()