mindspore.Tensor.inplace_update

Tensor.inplace_update(v, indices)[source]

Update some rows of a tensor with values of v according to the specified indices.

Note

indices refers to the left-most dimension.

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

  • indices (Union[int, tuple]) – Indices into the left-most dimension determining which rows to be updated.

Returns

Tensor, with updated values.

Raises
  • TypeError – if indices is not int or tuple.

  • TypeError – if indices is tuple but any of its element is not int.

  • ValueError – the Tensor shape is different from that of v.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> import mindspore
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
>>> v = Tensor(np.array([[0.1, 0.2], [0.3, 0.4]]), mindspore.float32)
>>> indices = (0, 1)
>>> output = x.inplace_update(v, indices)
>>> print(output)
[[0.1 0.2]
 [0.3 0.4]
 [5.  6. ]]