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

I have an array of numbers, and the maximum value may appear more than once.

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

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

+4
python arrays list numpy indexing
source share
1 answer
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]) 
+8
source share

All Articles