mindspore.ops.GatherNd

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

Gathers slices from a tensor by indices.

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

Inputs:
  • input_x (Tensor) - The target tensor to gather values.

  • indices (Tensor) - The index tensor, with int32 or int64 data type.

Outputs:

Tensor, has the same type as input_x and the shape is indices_shape[:-1] + x_shape[indices_shape[-1]:].

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> op = ops.GatherNd()
>>> input_x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]), mindspore.float32)
>>> indices = Tensor(np.array([[0, 0], [1, 1]]), mindspore.int32)
>>> output = op(input_x, indices)
>>> print(output)
[-0.1  0.5]