Grouping indices of unique elements in numpy

前端 未结 5 591
伪装坚强ぢ
伪装坚强ぢ 2021-01-17 17:15

I have many large (>100,000,000) lists of integers that contain many duplicates. I want to get the indices where each of the element occur. Currently I am doing something li

5条回答
  •  一向
    一向 (楼主)
    2021-01-17 17:56

    The numpy_indexed package (disclaimer: I am its author) implements a solution inspired by Jaime's; but with tests, a nice interface, and a lot of related functionality:

    import numpy_indexed as npi
    unique, idx_groups = npi.group_by(a, np.arange(len(a))
    

提交回复
热议问题