oneflow.add¶
-
oneflow.
add
(input, other, *, alpha=1) → Tensor¶ Adds other, scaled by alpha, to input. Scalar and broadcast promotation are supported.
\[out = input + alpha \times other\]- Parameters
input (Union[int, float, oneflow.Tensor]) – the input tensor.
other (Union[int, float, oneflow.Tensor]) – the tensor or number to add to input.
- Keyword Arguments
alpha (Number, optional) – the multiplier for other.
- Returns
the output Tensor.
- Return type
For example:
>>> import numpy as np >>> import oneflow as flow # element-wise add >>> x = flow.tensor(np.random.randn(2,3), dtype=flow.float32) >>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) >>> out = flow.add(x, y).numpy() >>> out.shape (2, 3) # scalar add >>> x = 5 >>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) >>> out = flow.add(x, y).numpy() >>> out.shape (2, 3) # broadcast add >>> x = flow.tensor(np.random.randn(1,1), dtype=flow.float32) >>> y = flow.tensor(np.random.randn(2,3), dtype=flow.float32) >>> out = flow.add(x, y).numpy() >>> out.shape (2, 3) # use alpha >>> x = flow.zeros(2, 3) >>> y = flow.ones(2, 3) >>> out = flow.add(x, y, alpha=10) >>> out tensor([[10., 10., 10.], [10., 10., 10.]], dtype=oneflow.float32)