Find indices of a list of values in a numpy array

后端 未结 1 1842
故里飘歌
故里飘歌 2021-01-04 13:50

I have a numpy master array. Given another array of search values, with repeating elements, I want to produce the indices of these search values in the master array.

<
相关标签:
1条回答
  • 2021-01-04 14:20

    Would np.searchsorted work for you ?

    >>> master = np.array([1,2,3,4,5])
    >>> search = np.array([4,2,2,3])
    >>> np.searchsorted(master, search)
    array([3, 1, 1, 2])
    
    0 讨论(0)
提交回复
热议问题