- unique_inverse(x: array, /) Tuple[array, array] ¶
Returns the unique elements of an input array
xand the indices from the set of unique elements that reconstruct
Data-dependent output shape
The shapes of two of the output arrays for this function depend on the data values in the input array; hence, array libraries which build computation graphs (e.g., JAX, Dask, etc.) may find this function difficult to implement without knowing array values. Accordingly, such libraries may choose to omit this function. See Data-dependent output shapes section for more details.
Uniqueness should be determined based on value equality (i.e.,
x_i == x_j). For input arrays having floating-point data types, value-based equality implies the following behavior.
nanvalues compare as
nanvalues should be considered distinct.
True, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return
As signed zeros are not distinct, using
inverse_indicesto reconstruct the input array is not guaranteed to return an array having the exact same values.
x (array) – input array. If
xhas more than one dimension, the function must flatten
xand return the unique elements of the flattened array.
out (Tuple[array, array]) – a namedtuple
first element must have the field name
valuesand must be an array containing the unique elements of
x. The array must have the same data type as
second element must have the field name
inverse_indicesand must be an array containing the indices of
x. The array must have the same shape as
xand have the default array index data type.
The order of unique elements is not specified and may vary between implementations.