oneflow.sub

oneflow.sub()

Computes the subtraction of input by other for each element, scalar and broadcast promotation are supported. The formula is:

\[out = input - other\]

For example:

>>> import numpy as np
>>> import oneflow as flow

# element-wise subtract
>>> input = flow.tensor(np.random.randn(2,3), dtype=flow.float32)
>>> other = flow.tensor(np.random.randn(2,3), dtype=flow.float32)
>>> out = flow.sub(input,other).numpy()
>>> out.shape
(2, 3)

# scalar subtract
>>> input = 5
>>> other = flow.tensor(np.random.randn(2,3), dtype=flow.float32)
>>> out = flow.sub(input,other).numpy()
>>> out.shape
(2, 3)

# broadcast subtract
>>> input = flow.tensor(np.random.randn(1,1), dtype=flow.float32)
>>> other = flow.tensor(np.random.randn(2,3), dtype=flow.float32)
>>> out = flow.sub(input,other).numpy()
>>> out.shape
(2, 3)