unique_consecutive#

ivy.unique_consecutive(x, /, *, axis=None)[source]#

Eliminates all but the first element from every consecutive group of equivalent elements in x.

Parameters:
  • x (Union[Array, NativeArray]) – input array.

  • axis (Optional[int], default: None) – the axis to apply unique on. If None, unique is applied on flattened x.

Return type:

Tuple[Union[Array, NativeArray], Union[Array, NativeArray], Union[Array, NativeArray]]

Returns:

ret – a namedtuple (output, inverse_indices, counts) whose - first element has the field name output and is an array

containing x with its equivalent consecutive elements eliminated.

  • second element has the field name inverse_indices and is an array containing the indices of output that reconstruct x.

  • third element has the field name counts and is an array containing the number of occurrences for each unique value or array in x.

Examples

With ivy.Array input: >>> x = ivy.array([1, 1, 2, 2, 3, 1, 1, 2]) >>> ivy..unique_consecutive(x) Results(values=ivy.array([1, 2, 3, 1, 2]),

inverse_indices=ivy.array([0, 0, 1, 1, 2, 3, 3, 4]), counts=ivy.array([2, 2, 1, 2, 1]))

Array.unique_consecutive(self, /, *, axis=None)[source]#

ivy.Array instance method variant of ivy.unique_consecutive.

This method simply wraps the function, and so the docstring for ivy.unique_consecutive also applies to this method with minimal changes.

Return type:

Tuple[Array, Array, Array]

Container.unique_consecutive(self, /, *, axis=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#

ivy.Container instance method variant of ivy.unique_consecutive.

This method simply wraps the function, and so the docstring for ivy.unique_consecutive also applies to this method with minimal changes.

Return type:

Container