Divide two tensors element-wise. The equation is: .. math:: out = x / y Note: ``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . .. _Introduction to Tensor: ../../guides/beginner/tenso
(
x: Tensor,
y: Tensor,
name: str | None = None,
*,
rounding_mode: str | None = None,
out: Tensor | None = None,
)
| 1025 | |
| 1026 | @param_two_alias(["x", "input"], ["y", "other"]) |
| 1027 | def divide( |
| 1028 | x: Tensor, |
| 1029 | y: Tensor, |
| 1030 | name: str | None = None, |
| 1031 | *, |
| 1032 | rounding_mode: str | None = None, |
| 1033 | out: Tensor | None = None, |
| 1034 | ) -> Tensor: |
| 1035 | """ |
| 1036 | Divide two tensors element-wise. The equation is: |
| 1037 | |
| 1038 | .. math:: |
| 1039 | out = x / y |
| 1040 | |
| 1041 | Note: |
| 1042 | ``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ . |
| 1043 | |
| 1044 | .. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor |
| 1045 | |
| 1046 | .. note:: |
| 1047 | Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``other`` can be used as an alias for ``y``. |
| 1048 | For example, ``divide(input=tensor_x, other=tensor_y)`` is equivalent to ``divide(x=tensor_x, y=tensor_y)``. |
| 1049 | |
| 1050 | Args: |
| 1051 | x (Tensor): the input tensor, it's data type should be bool, bfloat16, float16, float32, float64, |
| 1052 | int8, int16, int32, int64, uint8, complex64, complex128. |
| 1053 | alias: ``input``. |
| 1054 | y (Tensor): the input tensor, it's data type should be bool, bfloat16, float16, float32, float64, |
| 1055 | int8, int16, int32, int64, uint8, complex64, complex128. |
| 1056 | alias: ``other``. |
| 1057 | rounding_mode (str|None, optional): The rounding mode. Can be None (default), "trunc" (truncate toward zero), or "floor" (round down toward negative infinity). |
| 1058 | out (Tensor, optional): The output tensor. Default: None. |
| 1059 | name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
| 1060 | |
| 1061 | Returns: |
| 1062 | 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. |
| 1063 | |
| 1064 | Examples: |
| 1065 | |
| 1066 | .. code-block:: pycon |
| 1067 | |
| 1068 | >>> import paddle |
| 1069 | |
| 1070 | >>> x = paddle.to_tensor([2, 3, 4], dtype='float64') |
| 1071 | >>> y = paddle.to_tensor([1, 5, 2], dtype='float64') |
| 1072 | >>> z = paddle.divide(x, y) |
| 1073 | >>> print(z) |
| 1074 | Tensor(shape=[3], dtype=float64, place=Place(cpu), stop_gradient=True, |
| 1075 | [2. , 0.60000000, 2. ]) |
| 1076 | |
| 1077 | """ |
| 1078 | if rounding_mode is None: |
| 1079 | if in_dynamic_or_pir_mode(): |
| 1080 | res = _C_ops.divide(x, y, out=out) |
| 1081 | else: |
| 1082 | res = _elementwise_op(LayerHelper('elementwise_div', **locals())) |
| 1083 | |
| 1084 | return res |
no test coverage detected