mindspore.ops.InplaceSub

View Source On Gitee
class mindspore.ops.InplaceSub(indices)[source]

Subtracts v into specified rows of x. Computes \(y = x\); \(y[i,] -= input\_v\).

Refer to mindspore.ops.inplace_sub() for more details.

Parameters

indices (Union[int, tuple]) – Indices into the left-most dimension of x, and determines which rows of x to subtract by v. It is an integer or a tuple, whose value is in [0, the first dimension size of x).

Inputs:
  • x (Tensor) - The tensor to be subtracted. It has shape \((N,*)\) where \(*\) means any number of additional dimensions.

  • input_v (Tensor) - The value tensor subtract from x. It has the same dimension sizes as x except the first dimension, whose size must be the same as indices. It has the same data type with x.

Outputs:

Tensor, has the same shape and dtype as x.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor, ops
>>> indices = (0, 1)
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
>>> input_v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
>>> inplaceSub = ops.InplaceSub(indices)
>>> output = inplaceSub(x, input_v)
>>> print(output)
[[0.5 1. ]
 [2.  2.5]
 [5.  6. ]]