If you want a numpy response, you can use np.unique :
>>> unique,pos = np.unique(A,return_inverse=True)
Although if there are two elements with equal values, it just takes the first of the unique array.
With this, you can also easily sort by element like this:
>>> maxsort = counts.argsort()[::-1] >>> (unique[maxsort],counts[maxsort]) (array(['d', 'e', 'c', 'b', 'a'], dtype='|S1'), array([2, 1, 1, 1, 1]))
source share