bundles / numpy 2.4.3 / numpy / unique_counts
_ArrayFunctionDispatcher
numpy:unique_counts
Signature
def unique_counts ( x ) Summary
Find the unique elements and counts of an input array x.
Extended Summary
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.
Parameters
x: array_likeInput array. It will be flattened if it is not already 1-D.
Returns
out: namedtupleThe result containing:
values - The unique elements of an input array.
counts - The corresponding counts for each unique element.
Examples
import numpy as np x = [1, 1, 2] uniq = np.unique_counts(x) uniq.values uniq.counts✓
See also
- unique
Find the unique elements of an array.
Aliases
-
numpy.unique_counts