mindspore.ops.inplace_update

mindspore.ops.inplace_update(x, v, indices)[source]

Updates specified values in x to v according to indices.

Warning

This is an experimental API that is subject to change or deletion.

Note

indices can only be indexed along the highest dimension.

Parameters
  • x (Tensor) – A tensor which to be inplace updated. It can be one of the following data types: float32, float16 and int32.

  • v (Tensor) – A tensor with the same type as x and the same dimension size as x except the first dimension, which must be the same as the size of indices.

  • indices (Union[int, tuple[int], Tensor]) – Determines which rows of x to update with v, should be several int. It is an int or tuple or tensor with one dimension, whose value is in [-x.shape[0], x.shape[0]). If it is a tuple or Tensor, the size of 'indices' should be the same as the first dimension of 'v'.

Returns

Tensor, with the same type and shape as the input x.

Raises
  • TypeError – If indices is neither int nor tuple nor Tensor.

  • TypeError – If indices is a tuple or Tensor, but its element is not an int.

Supported Platforms:

GPU CPU

Examples

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