bundles / numpy latest / numpy / unique_inverse
_ArrayFunctionDispatcher
numpy:unique_inverse
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/lib/_arraysetops_impl.py :560
Signature
def unique_inverse ( x ) Summary
Find the unique elements of x and indices to reconstruct x.
Extended Summary
This function is an Array API compatible alternative to
np.unique(x, return_inverse=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.
inverse_indices - The indices from the set of unique elements that reconstruct
x.
Examples
import numpy as np x = [1, 1, 2] uniq = np.unique_inverse(x) uniq.values uniq.inverse_indices✓
See also
- unique
Find the unique elements of an array.
Aliases
-
numpy.unique_inverse