This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / unique_counts

_ArrayFunctionDispatcher

numpy:unique_counts

source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_arraysetops_impl.py :504

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_like

Input array. It will be flattened if it is not already 1-D.

Returns

out : namedtuple

The 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

Referenced by