mindspore.ops.tensor_scatter_sub

View Source On Gitee
mindspore.ops.tensor_scatter_sub(input_x, indices, updates)[source]

Return a new tensor by performing a subtraction update on input_x at the specified indices with the given update values.

\[output[indices] = input\_x - update\]

Note

On GPU, if some values of the indices are out of bound, instead of raising an index error, the corresponding updates will not be updated to self tensor. On CPU, if some values of the indices are out of bound, raising an index error. On Ascend, out of bound checking is not supported, if some values of the indices are out of bound, unknown errors may be caused.

Parameters
  • input_x (Tensor) – The input tensor.

  • indices (Tensor) – The specified indices. The rank must be at least 2.

  • updates (Tensor) – The update values.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([[1, 2, 3], [4, 5, 6]], mindspore.float32)
>>> indices = mindspore.tensor([[0, 0], [1, 1]])
>>> updates = mindspore.tensor([5, 5], mindspore.float32)
>>> mindspore.ops.tensor_scatter_sub(input, indices, updates)
Tensor(shape=[2, 3], dtype=Float32, value=
[[-4.00000000e+00,  2.00000000e+00,  3.00000000e+00],
 [ 4.00000000e+00,  0.00000000e+00,  6.00000000e+00]])