You can use np.unique to get the counts and an array of unique elements, then pull the elements whose count is max
import numpy as np a = np.array([0, 0, 15, 17, 16, 17, 16, 12, 18, 18]) un, cnt = np.unique(a, return_counts=True) print(un[cnt == cnt.max()]) [ 0 16 17 18]
un - unique elements, cnt - frequency / counter of each of them:
In [11]: a = np.array([0, 0, 15, 17, 16, 17, 16, 12, 18, 18]) In [12]: un, cnt = np.unique(a, return_counts=True) In [13]: un, cnt Out[13]: (array([ 0, 12, 15, 16, 17, 18]), array([2, 1, 1, 2, 2, 2]))
cnt == cnt.max() will give us a mask to pull out elements that are equal to max:
In [14]: cnt == cnt.max() Out[14]: array([ True, False, False, True, True, True], dtype=bool)