larray.Array.unique

Array.unique(self, axes=None, sort=False, sep='_')[source]

Returns unique values (optionally along axes)

Parameters:
axes : axis reference (int, str, Axis) or sequence of them, optional

Axis or axes along which to compute unique values. Defaults to None (all axes).

sort : bool, optional

Whether or not to sort unique values. Defaults to False. Sorting is not implemented yet for unique() along multiple axes.

sep : str, optional

Separator when several labels need to be combined. Defaults to ‘_’.

Returns:
Array

array with unique values

Examples

>>> arr = Array([[0, 2, 0, 0],
...               [1, 1, 1, 0]], 'a=a0,a1;b=b0..b3')
>>> arr
a\b  b0  b1  b2  b3
 a0   0   2   0   0
 a1   1   1   1   0

By default unique() returns the first occurrence of each unique value in the order it appears:

>>> arr.unique()
a_b  a0_b0  a0_b1  a1_b0
         0      2      1

To sort the unique values, use the sort argument:

>>> arr.unique(sort=True)
a_b  a0_b0  a1_b0  a0_b1
         0      1      2

One can also compute unique sub-arrays (i.e. combination of values) along axes. In our example the a0=0, a1=1 combination appears twice along the ‘b’ axis, so ‘b2’ is not returned:

>>> arr.unique('b')
a\b  b0  b1  b3
 a0   0   2   0
 a1   1   1   0
>>> arr.unique('b', sort=True)
a\b  b3  b0  b1
 a0   0   0   2
 a1   0   1   1