Find the unique elements and counts of an input array x.
This function is an Array API compatible alternative to:
np.unique(x, return_counts=True, equal_nan=False, sorted=False)
but returns a namedtuple for easier access to each output.
Note
This function currently always returns a sorted result, however, this could change in any NumPy minor release.
Input array. It will be flattened if it is not already 1-D.
The result containing:
See also
uniqueFind the unique elements of an array.
>>> import numpy as np >>> x = [1, 1, 2] >>> uniq = np.unique_counts(x) >>> uniq.values array([1, 2]) >>> uniq.counts array([2, 1])
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.unique_counts.html