I have need the N minimum (index) values in a numpy array

后端 未结 5 710
孤独总比滥情好
孤独总比滥情好 2021-02-05 02:57

Hi I have an array with X amount of values in it I would like to locate the indexs of the ten smallest values. In this link they calculated the maximum effectively, How to get i

5条回答
  •  一生所求
    2021-02-05 03:05

    If you call

    arr.argsort()[:3]
    

    It will give you the indices of the 3 smallest elements.

    array([0, 2, 1], dtype=int64)
    

    So, for n, you should call

    arr.argsort()[:n]
    

提交回复
热议问题