unique

Contents

unique#

class brainunit.math.unique(a, return_index=False, return_inverse=False, return_counts=False, axis=None, *, equal_nan=False, size=None, fill_value=None, **kwargs)#

Find the unique elements of a quantity or an array.

Parameters:
  • a (Union[Array, Quantity]) – Input array.

  • return_index (bool) – If True, also return the indices of a (along the specified axis, if provided) that result in the unique array.

  • return_inverse (bool) – If True, also return the indices of the unique array (for the specified axis, if provided) that can be used to reconstruct a.

  • return_counts (bool) – If True, also return the number of times each unique item appears in a.

  • axis (Optional[int]) – The axis along which to operate. If None, the array is flattened before use. Default is None.

  • equal_nan (bool) – Whether to compare NaN’s as equal. If True, NaN’s in a will be considered equal to each other in the unique array.

  • size (Optional[int]) – The length of the output array. If size is not None, the output array will have the length of size.

  • fill_value (Optional[ArrayLike, Quantity]) – The value to use for missing values. If fill_value is not None, the output array will have the length of size.

Returns:

res – The sorted unique values.

Return type:

Sequence[Array | Quantity] | Array | Quantity

Examples

>>> import saiunit as u
>>> a = [0, 1, 2, 1, 0] * u.second
>>> u.math.unique(a)