mindspore.ops.scatter_add
- mindspore.ops.scatter_add(input_x, indices, updates)[source]
Perform an addition update on input_x based on the specified indices and update values.
\[\text{input_x}[\text{indices}[i, ..., j], :] \mathrel{+}= \text{updates}[i, ..., j, :]\]Note
Support implicit type conversion and type promotion.
Since Parameter objects do not support type conversion, an exception will be thrown when input_x is of a low-precision data type.
The shape of updates is indices.shape + input_x.shape[1:].
- Parameters
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> input_x = mindspore.Parameter(mindspore.tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], ... mindspore.float32), name="x") >>> indices = mindspore.tensor([[0, 1], [1, 1]], mindspore.int32) >>> updates = mindspore.tensor([[[1.0, 1.0, 1.0], [3.0, 3.0, 3.0]], ... [[7.0, 7.0, 7.0], [9.0, 9.0, 9.0]]], mindspore.float32) >>> output = mindspore.ops.scatter_add(input_x, indices, updates) >>> print(output) [[ 1. 1. 1.] [19. 19. 19.]]