div

paddle. div ( x: Tensor, y: Tensor, name: str | None = None, *, rounding_mode: str | None = None, out: Tensor | None = None ) Tensor

Divide two tensors element-wise. The equation is:

\[out = x / y\]

Note

paddle.divide supports broadcasting. If you want know more about broadcasting, please refer to Introduction to Tensor .

Note

Alias Support: The parameter name input can be used as an alias for x, and other can be used as an alias for y. For example, divide(input=tensor_x, other=tensor_y) is equivalent to divide(x=tensor_x, y=tensor_y).

Parameters
  • x (Tensor) – the input tensor, it’s data type should be bool, bfloat16, float16, float32, float64, int8, int16, int32, int64, uint8, complex64, complex128. alias: input.

  • y (Tensor) – the input tensor, it’s data type should be bool, bfloat16, float16, float32, float64, int8, int16, int32, int64, uint8, complex64, complex128. alias: other.

  • rounding_mode (str|None, optional) – The rounding mode. Can be None (default), “trunc” (truncate toward zero), or “floor” (round down toward negative infinity).

  • out (Tensor, optional) – The output tensor. Default: None.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_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([2, 3, 4], dtype='float64')
>>> y = paddle.to_tensor([1, 5, 2], dtype='float64')
>>> z = paddle.divide(x, y)
>>> print(z)
Tensor(shape=[3], dtype=float64, place=Place(cpu), stop_gradient=True,
[2.        , 0.60000000, 2.        ])