MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / mul

Function mul

python/paddle/tensor/math.py:1302–1355  ·  view source on GitHub ↗

multiply two tensors element-wise. The equation is: .. math:: out = x * y Note: Supported shape of :attr:`x` and :attr:`y` for this operator: 1. `x.shape` == `y.shape`. 2. `x.shape` could be the continuous subsequence of `y.shape`. ``paddle.mul`

(
    x: Tensor, y: Tensor, name: str | None = None, *, out: Tensor | None = None
)

Source from the content-addressed store, hash-verified

1300
1301@param_two_alias(["x", "input"], ["y", "other"])
1302def mul(
1303 x: Tensor, y: Tensor, name: str | None = None, *, out: Tensor | None = None
1304) -> Tensor:
1305 """
1306 multiply two tensors element-wise. The equation is:
1307
1308 .. math::
1309 out = x * y
1310
1311 Note:
1312 Supported shape of :attr:`x` and :attr:`y` for this operator:
1313 1. `x.shape` == `y.shape`.
1314 2. `x.shape` could be the continuous subsequence of `y.shape`.
1315 ``paddle.mul`` supports broadcasting. If you would like to know more about broadcasting, please refer to `Introduction to Tensor`_ .
1316
1317 .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
1318
1319 Args:
1320 x (Tensor): the input tensor, its data type should be one of bfloat16, float16, float32, float64, int32, int64, bool, complex64, complex128.
1321 y (Tensor): the input tensor, its data type should be one of bfloat16, float16, float32, float64, int32, int64, bool, complex64, complex128.
1322 name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
1323
1324 Keyword Args:
1325 out (Tensor|None, optional): The output tensor. If set, the result will be stored in this tensor. Default is None.
1326
1327 Returns:
1328 N-D Tensor. A location into which the result is stored. If :attr:`x`, :attr:`y` have different shapes and are "broadcastable", the resulting tensor shape is the shape of :attr:`x` and :attr:`y` after broadcasting. If :attr:`x`, :attr:`y` have the same shape, its shape is the same as :attr:`x` and :attr:`y`.
1329
1330 Examples:
1331
1332 .. code-block:: pycon
1333
1334 >>> import paddle
1335
1336 >>> x = paddle.to_tensor([[1, 2], [3, 4]])
1337 >>> y = paddle.to_tensor([[5, 6], [7, 8]])
1338 >>> res = paddle.mul(x, y)
1339 >>> print(res)
1340 Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
1341 [[5 , 12],
1342 [21, 32]])
1343 >>> x = paddle.to_tensor([[[1, 2, 3], [1, 2, 3]]])
1344 >>> y = paddle.to_tensor([2])
1345 >>> res = paddle.mul(x, y)
1346 >>> print(res)
1347 Tensor(shape=[1, 2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
1348 [[[2, 4, 6],
1349 [2, 4, 6]]])
1350
1351 """
1352 if in_dynamic_or_pir_mode():
1353 return _C_ops.multiply(x, y, out=out)
1354 else:
1355 return _elementwise_op(LayerHelper('elementwise_mul', **locals()))
1356
1357
1358@param_two_alias(["x", "input"], ["y", "other"])

Callers

nothing calls this directly

Calls 3

in_dynamic_or_pir_modeFunction · 0.85
_elementwise_opFunction · 0.85
LayerHelperClass · 0.85

Tested by

no test coverage detected