Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Problem description

Agree to Privacy Statement

mindspore.ops.unique_consecutive

mindspore.ops.unique_consecutive(x, return_idx=False, return_counts=False, axis=None)[source]

Returns the elements that are unique in each consecutive group of equivalent elements in the input tensor.

Parameters
  • x (Tensor) – The input tensor.

  • return_idx (bool, optional) – Whether to return the indices of the end position of each element in the original input list in the returned unique list. Default: False.

  • return_counts (bool, optional) – Whether to return the counts of each unique element. Default: False.

  • axis (int, optional) – The dimension to apply unique. If None, the unique of the flattened input is returned. If specified, it must be int32 or int64. Default: None.

Returns

A tensor or a tuple of tensors containing tensor objects (output, idx, counts). output has the same type as x and is used to represent the output list of unique scalar elements. If return_idx is True, there will be an additional returned tensor, idx, which has the same shape as x and represents the index of where the element in the original input maps to the position in the output. If return_counts is True, there will be an additional returned tensor, counts, which represents the number of occurrences for each unique value or tensor.

Raises
  • TypeError – If x is not a Tensor.

  • RuntimeError – If axis is not in the range of [ndim,ndim1].

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindspore import ops
>>> from mindspore import Tensor
>>> from mindspore import dtype as mstype
>>> x = Tensor(np.array([1, 1, 2, 2, 3, 1, 1, 2]), mstype.int32)
>>> output, idx, counts = ops.unique_consecutive(x, True, True, None)
>>> print(output)
[1 2 3 1 2]
>>> print(idx)
[0 0 1 1 2 3 3 4]
>>> print(counts)
[2 2 1 2 1]