mindspore.ops.sub
- mindspore.ops.sub(input, other)[source]
Subtract the second input from the first input element-wise.
\[out_{i} = input_{i} - other_{i}\]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), Tensor(np.array([True]))] are all considered bool type.
Support implicit type conversion and type promotion.
Warning
Starting after version 2.9.0, an optional keyword argument alpha will be added. The signature will change to
mindspore.ops.sub(input, other, *, alpha=1). The alpha parameter is a scalar multiplier for other, and the formula will become \(out_{i} = input_{i} - alpha \times other_{i}\). This change is backward-compatible; behavior is unchanged when alpha is not specified.- Parameters
- Returns
Tensor
- Supported Platforms:
AscendGPUCPU
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]