NumPy: Comparing Elements in Two Arrays

后端 未结 6 393
不思量自难忘°
不思量自难忘° 2020-12-02 12:57

Anyone ever come up to this problem? Let\'s say you have two arrays like the following

a = array([1,2,3,4,5,6])
b = array([1,4,5])

Is there

6条回答
  •  醉酒成梦
    2020-12-02 13:49

    Your example implies set-like behavior, caring more about existance in the array than having the right element at the right place. Numpy does this differently with its mathematical arrays and matrices, it will tell you only about items at the exact right spot. Can you make that work for you?

    >>> import numpy
    >>> a = numpy.array([1,2,3])
    >>> b = numpy.array([1,3,3])
    >>> a == b
    array([ True, False,  True], dtype=bool)
    

提交回复
热议问题