I have two lists of tuples and I want to find which elements from the first are in the second one. For example:
elements =
[(903, 468),
(913, 468),
(926, 468),
(833, 470),
(903, 470),
(917, 470),
(833, 833),
(903, 833),
(913, 833),
(917, 833)]
test_elements =
[(903, 468),
(913, 468),
(833, 470),
(903, 470),
(833, 833),
(903, 833)]
and I want to return a boolean mask for the elements in elements
that exist in test_elements
. I dont understand why np.isin doesnt give the correct result:
list(map(np.all, np.isin(elements, test_elements)))
>>> [True, True, False, True, True, False, True, True, True, False]
which means that (913, 833)
should be in test_elements
but this is not true
This expesssion however (which I found from another post here) returns the correct mask:
list((np.array(elements)[:,None] == np.array(test_elements)).all(2).any(1))
>>> [True, True, False, True, True, False, True, True, False, False]
What am I missing with np.isin
please?