mindspore.ops.GatherD

View Source On Gitee
class mindspore.ops.GatherD[source]

Gathers elements along an axis specified by dim.

Refer to mindspore.ops.gather_elements() for more details.

Inputs:
  • x (Tensor) - The input tensor.

  • dim (int) - The axis along which to index. It must be int32 or int64.

  • index (Tensor) - The indices of elements to gather. It can be one of the following data types: int32, int64. The value range of each index element is [-x_rank[dim], x_rank[dim]).

Outputs:

Tensor, has the same data type with x.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[1, 2], [3, 4]]), mindspore.int32)
>>> index = Tensor(np.array([[0, 0], [1, 0]]), mindspore.int32)
>>> dim = 1
>>> output = ops.GatherD()(x, dim, index)
>>> print(output)
[[1 1]
 [4 3]]