mindspore.ops.gather_d

查看源文件
mindspore.ops.gather_d(x, dim, index)[源代码]

获取指定轴的元素。 有关更多详细信息,请参阅 mindspore.ops.gather_elements()

支持平台:

Ascend GPU CPU

样例:

>>> 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.gather_d(x, dim, index)
>>> print(output)
[[1 1]
 [4 3]]