add¶
- paddle. add ( x, y, name=None ) [source]
-
Elementwise Add Operator. Add two tensors element-wise The equation is:
\[Out=X+Y\]$X$ the tensor of any dimension. $Y$ the tensor whose dimensions must be less than or equal to the dimensions of $X$.
This operator is used in the following cases:
The shape of $Y$ is the same with $X$.
The shape of $Y$ is a continuous subsequence of $X$.
For example:
shape(X) = (2, 3, 4, 5), shape(Y) = (,) shape(X) = (2, 3, 4, 5), shape(Y) = (5,) shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2 shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1 shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0 shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
- Parameters
-
x (Tensor) – Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64.
y (Tensor) – Tensor or LoDTensor of any dimensions. Its dtype should be int32, int64, float32, float64.
name (string, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.
- Returns
-
N-D Tensor. A location into which the result is stored. It’s dimension equals with x.
Examples
>>> import paddle >>> x = paddle.to_tensor([2, 3, 4], 'float64') >>> y = paddle.to_tensor([1, 5, 2], 'float64') >>> z = paddle.add(x, y) >>> print(z) Tensor(shape=[3], dtype=float64, place=Place(cpu), stop_gradient=True, [3., 8., 6.])