How to return all the minimum indices in numpy

后端 未结 4 465
深忆病人
深忆病人 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:50

    See the documentation for numpy.argmax (which is referred to by the docs for numpy.argmin):

    In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.

    The phrasing of the documentation ("indices" instead of "index") refers to the multidimensional case when axis is provided.

    So, you can't do it with np.argmin. Instead, this will work:

    np.where(arr == arr.min())
    

提交回复
热议问题