Numpy Array: Efficiently find matching indices

前端 未结 3 758
一生所求
一生所求 2021-01-12 18:11

I have two lists, one of which is massive (millions of elements), the other several thousand. I want to do the following

bigArray=[0,1,0,2,3,2,,.....]

small         


        
3条回答
  •  旧时难觅i
    2021-01-12 18:59

    Numpy provides the function numpy.searchsorted: http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.searchsorted.html

    Example:

    >>> import numpy as np
    >>> sorted = np.argsort(big_list)
    >>> r = np.searchsorted(big_list, small_list, side='right',sorter=sorted)
    >>> l  = np.searchsorted(big_list, small_list, side='left',sorter=sorted)
    >>> for b, e in zip(l, r):
    ...     inds = sorted[b:e]
    

提交回复
热议问题