flopscope.

flopscope.numpy.unique_all

fnp.unique_all(x: 'ArrayLike', /) -> 'Any'[flopscope source][numpy source]

Find the unique elements of an array, and counts, inverse, and indices.

Adapted from NumPy docs np.unique_all

Areacore
Typecustom
NumPy Refnp.unique_all
Cost
per-operation
Flopscope Context

Sort-based unique; cost = n*ceil(log2(n)).

This function is an Array API compatible alternative to:

flops.unique(x, return_index=True, return_inverse=True,
          return_counts=True, equal_nan=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.

  • indices - The first occurring indices for each unique element.

  • inverse_indices - The indices from the set of unique elements that reconstruct x.

  • counts - The corresponding counts for each unique element.

See also

Examples

>>> import flopscope.numpy as fnp
>>> x = [1, 1, 2]
>>> uniq = flops.unique_all(x)
>>> uniq.values
array([1, 2])
>>> uniq.indices
array([0, 2])
>>> uniq.inverse_indices
array([0, 0, 1])
>>> uniq.counts
array([2, 1])