mindspore.ops.index_add
- mindspore.ops.index_add(x, indices, y, axis, use_lock=True, check_index_bound=True)[source]
Add the elements of input y into input x along the given axis and indices.
Note
indices is a one-dimensional tensor, and
.The value range of the elements in indices is
.
- Parameters
x (Union[Parameter, Tensor]) – The input parameter or tensor.
indices (Tensor) – The specified indices.
y (Tensor) – The input tensor to add to x.
axis (int) – The specified axis.
use_lock (bool, optional) – Whether to enable a lock to protect the updating process of variable tensors. Default
True
.check_index_bound (bool, optional) – Whether to check index boundary. Default
True
.
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> x = mindspore.Parameter(mindspore.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], mindspore.float32), ... name="name_x") >>> indices = mindspore.tensor([0, 2], mindspore.int32) >>> y = mindspore.tensor([[0.5, 1.0], [1.0, 1.5], [2.0, 2.5]], mindspore.float32) >>> output = mindspore.ops.index_add(x, indices, y, 1) >>> print(output) [[ 1.5 2. 4. ] [ 5. 5. 7.5] [ 9. 8. 11.5]]