idtopick is an array of ids
idtopick=array([50,48,12,125,3458,155,299,6,7,84,58,63,0,8,-1])
idtolook is another array containing the ids I’m interested in
idtolook=array([0,8,12,50])
I would like to store in another array the positions of idtopick that corresponds to idtolook.
This is my solution
positions=array([where(idtopick==dummy)[0][0] for dummy in idtolook])
Resulting in
array([12, 13, 2, 0])
It works but in reality the arrays I’m working with store millions of point so the above script is rather slow. I would like to know if there’s a way to make it faster. Also, I want to keep the order of idtolook so any algorithm that would sort it wouldn’t work for my case.
You can use sorting:
Note that it won’t throw an error though if there is and
idtolookmissing inidtopick. You could actually sort idtolook into the results array too, which should be faster:Which has similarity to the set operations.