atan2¶
- paddle. atan2 ( x, y, name=None ) [source]
-
Element-wise arctangent of x/y with consideration of the quadrant.
- Equation:
-
\[\begin{split}atan2(x,y)=\left\{\begin{matrix} & tan^{-1}(\frac{x}{y}) & y > 0 \\ & tan^{-1}(\frac{x}{y}) + \pi & x>=0, y < 0 \\ & tan^{-1}(\frac{x}{y}) - \pi & x<0, y < 0 \\ & +\frac{\pi}{2} & x>0, y = 0 \\ & -\frac{\pi}{2} & x<0, y = 0 \\ &\text{undefined} & x=0, y = 0 \end{matrix}\right.\end{split}\]
- Parameters
-
x (Tensor) – An N-D Tensor, the data type is int32, int64, float16, float32, float64.
y (Tensor) – An N-D Tensor, must have the same type as x.
name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
An N-D Tensor, the shape and data type is the same with input (The output data type is float64 when the input data type is int).
- Return type
-
out (Tensor)
Examples
>>> import paddle >>> x = paddle.to_tensor([-1, +1, +1, -1]).astype('float32') >>> x Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, [-1, 1, 1, -1]) >>> y = paddle.to_tensor([-1, -1, +1, +1]).astype('float32') >>> y Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, [-1, -1, 1, 1]) >>> out = paddle.atan2(x, y) >>> out Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True, [-2.35619450, 2.35619450, 0.78539819, -0.78539819])