I'm referring to a similar question: Find indices of a list of values in a numpy array
In that case we have a master array that is sorted and another array of which we want to find the index in the master array.
master = np.array([1,2,3,4,5])
search = np.array([4,2,2,3])
The suggested solution was:
>>> master = np.array([1,2,3,4,5])
>>> search = np.array([4,2,2,3])
>>>np.searchsorted(master, search)
array([3, 1, 1, 2])
But what if master is not sorted? for example if i have two arrays like this where the first one is not sorted:
>>>master = np.array([2,3,5,4,1])
>>>search = np.array([3,2,1,4,5])
i get:
>>> np.searchsorted(master, search)
array([1, 0, 0, 2, 5])
But instead i would like:
array([1,0,4,3,2])
i.e. the indices of items in search in master.
How do i get them possibly with a native function of numpy?(not using [np.where(master==i) for i in search] )
Thanks
EDIT: In this case the search array is a permutation of master. Then i would like to find how the index of master are permuted to give a permuted array like search.
As general case, search array contain some item that maybe contained or not in the master such as:
>>>master = np.array([2,3,5,4,1])
>>>search = np.array([1,4,7])
searchsortedassumes the input to be sorted (like in binary search).