mindspore.ops.scatter_add
- mindspore.ops.scatter_add(input_x, indices, updates)[source]
Using given values to update tensor value through the add operation, along with the input indices. This operation outputs the input_x after the update is done, which makes it convenient to use the updated value.
- Parameters
input_x (Parameter) – The target tensor, with data type of Parameter. The shape is \((N, *)\) where \(*\) means,any number of additional dimensions.
indices (Tensor) – The index to do add operation whose data type must be int32 or int64.
updates (Tensor) – The tensor doing the add operation with input_x, the data type is same as input_x, the shape is indices.shape + x.shape[1:].
- Returns
Tensor, the updated input_x, has the same shape and type as input_x.
- Raises
TypeError – If indices is not an int32 or int64.
ValueError – If the shape of updates is not equal to indices.shape + input_x.shape[1:].
RuntimeError – If the data type of input_x and updates conversion of Parameter is required when data type conversion of Parameter is not supported.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor, Parameter >>> from mindspore import ops >>> input_x = Parameter(Tensor(np.array([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), mindspore.float32), name="x") >>> indices = Tensor(np.array([[0, 1], [1, 1]]), mindspore.int32) >>> updates = Tensor(np.array([[[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 = ops.scatter_add(input_x, indices, updates) >>> print(output) [[ 1. 1. 1.] [19. 19. 19.]]