Use np.random.choice -
np.random.choice(np.flatnonzero(b == b.max()))
Let the array with three maximum candidates be checked -
In [298]: b Out[298]: array([0, 5, 2, 5, 4, 5]) In [299]: c=[np.random.choice(np.flatnonzero(b == b.max())) for i in range(100000)] In [300]: np.bincount(c) Out[300]: array([ 0, 33180, 0, 33611, 0, 33209])
source share