mindspore.ops.InplaceIndexAdd
- class mindspore.ops.InplaceIndexAdd(axis)[source]
Adds Tensor updates to specified axis and indices of Tensor var element-wise.
Warning
This is an experimental API that is subject to change or deletion.
Refer to
mindspore.ops.inplace_index_add()
for more details.- Parameters
axis (int) – The dimension along which to index. It should be in range \([0, len(var.dim))\).
- Inputs:
var (Parameter) - The input Parameter to add to, with data type uint8, int8, int16, int32, float16, float32, float64.
indices (Tensor) - The indies along axis to perform the addition. A 1D Tensor of shape \((updates.shape[axis],)\), every value of it should be in range \([0, var.shape[axis])\) with data type int32.
updates (Tensor) - The input Tensor with the value to add. Must have same data type as var. The shape must be the same as var except the axis th dimension.
- Outputs:
Tensor, updated result, has the same shape and dtype as var.
- Supported Platforms:
Ascend
CPU
Examples
>>> var = Parameter(Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)) >>> indices = Tensor(np.array([0, 1]), mindspore.int32) >>> updates = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32) >>> inplaceIndexAdd = ops.InplaceIndexAdd(axis=0) >>> var = inplaceIndexAdd(var, indices, updates) >>> print(var) [[1.5 3. ] [4. 5.5] [5. 6. ]]