Issue
Why does this piece of code return True
when it clearly can be seen that the element [1, 1]
is not present in the first array and what am I supposed to change in order to make it return False
?
aux = np.asarray([[0, 1], [1, 2], [1, 3]])
np.asarray([1, 1]) in aux
True
Solution
Checking for equality for the two arrays broadcasts the 1d array so the ==
operator checks if the corresponding indices are equal.
>>> np.array([1, 1]) == aux
array([[False, True],
[ True, False],
[ True, False]])
Since none of the inner arrays are all True
, no array in aux
is completely equal to the other array. We can check for this using
np.any(np.all(np.array([1, 1]) == aux, axis=1))
Answered By - rchome
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.