numpy.argmax:如果多次出现最大值,如何获取与* last *出现相对应的索引

时间:2011-08-12 10:44:21

标签: python arrays list numpy indexing

我有一个数字数组,最大值可能会多次出现。

是否可以通过使用像numpy.argmax这样的东西来找到最后一次出现的最大值的索引?

或者,更好的是,是否可以获得数组中所有最大值出现的索引列表?

1 个答案:

答案 0 :(得分:8)

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])