numpy/numpy — pull request #4180 by jaimefrio (2014-01-09 18:28:46+00:00)
Title: ENH: add a 'return_counts=' keyword argument to `np.unique`

This PR adds a new keyword argument to `np.unique` that returns the number of
times each unique item comes up in the array. This allows replacing a typical
numpy construct:

unq, _ = np.unique(a, return_inverse=True)
unq_counts = np.bincount(_)

with a single line of code:

unq, unq_counts = np.unique(a, return_counts=True)

As a plus, it runs faster, because it does not need the extra operations
required to produce `unique_inverse`.