numpy isin 筛选所有在范围内的 2020-05-06
2020-05-06 本文已影响0人
五道口的程序狐
可以进行逐个元素的判断,判断这些东西有没有在给定的数组中。
>>> 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()