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.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.mint.gather

mindspore.mint.gather(input, dim, index)[source]

Gather data from a tensor by indices.

output[(i0,i1,...,idim,idim+1,...,in)]=input[(i0,i1,...,index[(i0,i1,...,idim,idim+1,...,in)],idim+1,...,in)]

Warning

On Ascend, the behavior is unpredictable in the following cases:

  • the value of index is not in the range [-input.shape[dim], input.shape[dim]) in forward;

  • the value of index is not in the range [0, input.shape[dim]) in backward.

Parameters
  • input (Tensor) – The target tensor to gather values.

  • dim (int) – the axis to index along, must be in range [-input.rank, input.rank).

  • index (Tensor) –

    The index tensor, with int32 or int64 data type. An valid index should be:

    • index.rank == input.rank;

    • for axis != dim, index.shape[axis] <= input.shape[axis];

    • the value of index is in range [-input.shape[dim], input.shape[dim]).

Returns

Tensor, has the same type as input and the same shape as index.

Raises
  • ValueError – If the shape of index is illegal.

  • ValueError – If dim is not in [-input.rank, input.rank).

  • ValueError – If the value of index is out of the valid range.

  • TypeError – If the type of index is illegal.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> from mindspore.ops.function.array_func import gather_ext
>>> input = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32)
>>> index = Tensor(np.array([[0, 0], [1, 1]]), mindspore.int32)
>>> output = gather_ext(input, 1, index)
>>> print(output)
[[-0.1 -0.1]
 [0.5   0.5]]