I have two sets of coordinates and want to find out which coordinates of the coo
set are identical to any coordinate in the targets
set. I want to know the indices in the coo
set which means I'd like to get a list of indices or of bools.
import numpy as np
coo = np.array([[1,2],[1,6],[5,3],[3,6]]) # coordinates
targets = np.array([[5,3],[1,6]]) # coordinates of targets
print(np.isin(coo,targets))
[[ True False]
[ True True]
[ True True]
[ True True]]
The desired result would be one of the following two:
[False True True False] # bool list
[1,2] # list of concerning indices
My problem is, that ...
np.isin
has noaxis
-attribute so that I could useaxis=1
.- even applying logical and to each row of the output would return
True
for the last element, which is wrong.
I am aware of loops and conditions but I am sure Python is equipped with ways for a more elegant solution.