numpy.argmax
only returns the index of the first occurrence. You could apply argmax
to a reversed view of the array:
import numpy as np
a = np.array([0,0,4,4,4,4,2,2,2,2])
b = a[::-1]
i = len(b) - np.argmax(b) - 1
i # 5
a[i:] # array([4, 2, 2, 2, 2])
Note numpy doesn't copy the array but instead creates a view of the original with a stride that accesses it in reverse order.
id(a) == id(b.base) # True
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…