mindspore.ops.inplace_index_add

View Source On Gitee
mindspore.ops.inplace_index_add(var, indices, updates, axis)[source]

Add updates to var according to the indices and axis.

for each i, …, j in indices :

x[:,indices[i,...,j],:]+=v[:,i,...,j,:]

where i is the index of the element in indices, and the axis of indices[i] is determined by the input axis.

Parameters
  • var (Union[Parameter, Tensor]) – The input parameter or tensor.

  • indices (Tensor) – The specified indices, a 1-D tensor.

  • updates (Tensor) – The input tensor to add to var.

  • axis (int) – The specified axis.

Returns

Tensor

Supported Platforms:

Ascend CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> var = mindspore.Parameter(mindspore.tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32))
>>> indices = mindspore.tensor(np.array([0, 1]), mindspore.int32)
>>> updates = mindspore.tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
>>> mindspore.ops.inplace_index_add(var, indices, updates, axis=0)
>>> print(var.asnumpy())
[[1.5 3. ]
 [4.  5.5]
 [5.  6. ]]