mindspore.ops.InplaceSub

class mindspore.ops.InplaceSub(indices)[源代码]

Subtracts v into specified rows of x. Computes y = x; y[i,] -= v.

Parameters

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

Inputs:
  • x (Tensor) - The first input is a tensor whose data type is float16, float32 or int32. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank should be less than 8.

  • input_v (Tensor) - The second input is a tensor who has the same dimension sizes as x except the first dimension, which must be the same as indices’ size. It has the same data type with x.

Outputs:

Tensor, has the same shape and dtype as x.

Raises
  • TypeError – If indices is neither int nor tuple.

  • TypeError – If indices is a tuple whose elements are not all int.

  • ValueError – If length of shape of x is not equal to length of shape of input_v.

Supported Platforms:

Ascend

Examples

>>> 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. ]]