multiply¶
- paddle. multiply ( x, y, name=None ) [source]
-
multiply two tensors element-wise. The equation is:
\[out = x * y\]Note
paddle.multiply
supports broadcasting. If you would like to know more about broadcasting, please refer to Introduction to Tensor .- Parameters
-
x (Tensor) – the input tensor, its data type should be one of float32, float64, int32, int64, bool.
y (Tensor) – the input tensor, its data type should be one of float32, float64, int32, int64, bool.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
N-D Tensor. A location into which the result is stored. If x, y have different shapes and are “broadcastable”, the resulting tensor shape is the shape of x and y after broadcasting. If x, y have the same shape, its shape is the same as x and y.
Examples
import paddle x = paddle.to_tensor([[1, 2], [3, 4]]) y = paddle.to_tensor([[5, 6], [7, 8]]) res = paddle.multiply(x, y) print(res) # [[5, 12], [21, 32]] x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]]) y = paddle.to_tensor([2]) res = paddle.multiply(x, y) print(res) # [[[2, 4, 6], [2, 4, 6]]]