How to return all the minimum indices in numpy

后端 未结 4 444
深忆病人
深忆病人 2020-12-03 00:51

I am a little bit confused reading the documentation of argmin function in numpy. It looks like it should do the job:

Reading this

Return the

4条回答
  •  春和景丽
    2020-12-03 01:31

    Assuming that you want the indices of a list, not a numpy array, try

    my_list = [5, 3, 2, 1, 1, 1, 6, 1]
    np.where(my_list == min(my_list))[0]
    

    The index [0] is because numpy returns a tuple of your answer and nothing (answer as a numpy array). Don't ask me why.

提交回复
热议问题