unique_counts¶
- unique_counts(x: array, /) Tuple[array, array]¶
Returns the unique elements of an input array
xand the corresponding counts for each unique element inx.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.
Note
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.As
nanvalues compare asFalse,nanvalues should be considered distinct.As
-0and+0compare asTrue, signed zeros should not be considered distinct, and the corresponding unique element will be implementation-dependent (e.g., an implementation could choose to return-0if-0occurs before+0).
Each
nanvalue should have a count of one, while the counts for signed zeros should be aggregated as a single count.- Parameters:
x (array) – input array. If
xhas more than one dimension, the function must flattenxand return the unique elements of the flattened array.- Returns:
out (Tuple[array, array]) – a namedtuple
(values, counts)whosefirst element must have the field name
valuesand must be an array containing the unique elements ofx. The array must have the same data type asx.second element must have the field name
countsand must be an array containing the number of times each unique element occurs inx. The returned array must have same shape asvaluesand must have the default array index data type.
Note
The order of unique elements is not specified and may vary between implementations.