mindspore.ops.subtract

mindspore.ops.subtract(x, other, *, alpha=1)[source]

Performs the element-wise subtraction of input tensors.

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

  • other (Union[Tensor, number.Number]) – The tensor or number to be subtracted.

Keyword Arguments

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

Returns

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

Raises

TypeErrorx or other is neither Tensor nor number.Number.

Supported Platforms:

Ascend GPU CPU

Examples

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