mindspore.ops.sub
- mindspore.ops.sub(input, other)[源代码]
逐元素计算第一个输入减去第二个输入的值。
说明
当两个输入具有不同的shape时,它们的shape必须要能广播为一个共同的shape。
两个输入不能同时为bool类型。[True, Tensor(True, bool_), Tensor(np.array([True]), bool_)]等都为bool类型。
支持隐式类型转换,类型提升。
- 参数:
input (Union[Tensor, number.Number, bool]) - 第一个输入。
other (Union[Tensor, number.Number, bool]) - 第二个输入。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> 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]