Given an numpy array a, I can use np.unique(a) to generate the unique values included in a. How can I get the count of each unique values included in a?
1 Answer
Since you mentioned np.unique, it accepts a second argument called return_counts:
u, c = np.unique(a, return_counts=True)
c[i] is the corresponding count for u[i].
from collections import Counterthenprint(Counter(a))