mindspore.ops.sub

View Source On Gitee
mindspore.ops.sub(input, other)[source]

Subtract the second input from the first input element-wise.

outi=inputiotheri

Note

  • When the two inputs have different shapes, they must be able to broadcast to a common shape.

  • The two inputs can not be bool type at the same time, [True, Tensor(True, bool_), Tensor(np.array([True]), bool_)] are all considered bool type.

  • Support implicit type conversion and type promotion.

Parameters
  • input (Union[Tensor, number.Number, bool]) – The first input.

  • other (Union[Tensor, number.Number, bool]) – The second input.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([1, 2, 3], mindspore.int32)
>>> other = mindspore.tensor([4, 5, 6], mindspore.int32)
>>> output = mindspore.ops.sub(input, other)
>>> print(output)
[-3 -3 -3]