I'm trying to get the top N maximum values in a numpy array, with random tie-breaking if the values are equal.
I can get the top N maximum values as follows (taken from here), but this code always returns the first "4" (ie, index 1). Is there a way to make it choose randomly amongst the 4s?
>>> a
array([9, 4, 4, 3, 3, 9, 0, 4, 6, 0])
>>> ind = np.argpartition(a, -4)[-4:]
>>> ind
array([1, 5, 8, 0])