mindspore.ops.subtract

View Source On Gitee
mindspore.ops.subtract(input, other, *, alpha=1)[source]

Performs the element-wise subtract of input tensors.

\[output[i] = input[i] - alpha * other[i]\]
Parameters
  • input (Union[Tensor, number.Number]) – Tensor or Number involved in subtraction.

  • other (Union[Tensor, number.Number]) – Tensor or Number involved in subtraction.

Keyword Arguments

alpha (Number) – The multiplier for \(other\). Default: 1 .

Returns

Tensor, has the same shape and dtype as input tensors.

Raises
  • TypeErrorinput or other is neither Tensor nor number.Number.

  • TypeError – Both input and other are not Tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input = Tensor(np.array([4, 5, 6]), mindspore.float32)
>>> y = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> z = ops.subtract(input, y, alpha=1)
>>> print(z)
[3. 3. 3.]