atan2

paddle. atan2 ( x, y, name=None ) [source]

Element-wise arctangent of x/y with consideration of the quadrant.

Equation:
atan2(x,y)={tan1(xy)y>0tan1(xy)+πx>=0,y<0tan1(xy)πx<0,y<0+π2x>0,y=0π2x<0,y=0undefinedx=0,y=0
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')
#Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
#       [-1,  1,  1, -1])

y = paddle.to_tensor([-1, -1, +1, +1]).astype('float32')
#Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
#       [-1,  -1,  1, 1])

out = paddle.atan2(x, y)
#Tensor(shape=[4], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
#       [-2.35619450,  2.35619450,  0.78539819, -0.78539819])