numpy.argmax: how to get the index corresponding to the *last* occurrence, in case of multiple occurrences of the maximum values

自古美人都是妖i 提交于 2019-12-21 17:27:45

问题


I have an array of numbers, and the maximum value might occurrence more than once.

Is it possible to find the index of the last occurrence of the maximum value by using something like numpy.argmax?

Or, even better, is it possible to get a list of indices of all the occurrences of the maximum value in the array?


回答1:


import numpy as np

a = np.array((1,2,3,2,3,2,1,3))

occurences = np.where(a == a.max())

# occurences == array([2, 4, 7])


来源:https://stackoverflow.com/questions/7038975/numpy-argmax-how-to-get-the-index-corresponding-to-the-last-occurrence-in-ca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!