mindspore.ops.inplace_update

mindspore.ops.inplace_update(x, v, indices)[源代码]

根据索引将 x 更新为 v

警告

这是一个实验性API,后续可能修改或删除。

对于 indices 的每个元素下标 \(i, ..., j\)

\[x[\text{index}[i, ..., j]] = v[i, ..., j]\]
参数:
  • x (Tensor) - 输入tensor。

  • v (Tensor) - 更新的tensor。

  • indices (Union[int, tuple[int], Tensor]) - 对输入 x 沿第0维度的索引。

返回:

Tensor

支持平台:

GPU CPU

样例:

>>> import mindspore
>>> indices = (0, 1)
>>> x = mindspore.tensor([[1, 2], [3, 4], [5, 6]], mindspore.float32)
>>> v = mindspore.tensor([[0.5, 1.0], [1.0, 1.5]], mindspore.float32)
>>> output = mindspore.ops.inplace_update(x, v, indices)
>>> print(output)
[[0.5 1. ]
 [1.  1.5]
 [5.  6. ]]