python: check if an numpy array contains any element of another array

后端 未结 3 1211
长情又很酷
长情又很酷 2021-02-13 12:08

What is the best way to check if an numpy array contains any element of another array?

example:

array1 = [10,5,4,13,10,1,1,22,7,3,15,9]
array2 = [3,4,9,1         


        
3条回答
  •  日久生厌
    2021-02-13 12:53

    You can use any built-in function and list comprehension:

    >>> array1 = [10,5,4,13,10,1,1,22,7,3,15,9]
    >>> array2 = [3,4,9,10,13,15,16,18,19,20,21,22,23]
    >>> any(i in array2 for i in array1)
    True
    

提交回复
热议问题