atan2

paddle. atan2 ( x, y, name=None ) [源代码]

对 x/y 进行逐元素的 arctangent 运算,通过符号确定象限

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

参数

  • x (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64。

  • y (Tensor) - 输入的 Tensor,数据类型为:int32、int64、float16、float32、float64。

  • name (str,可选) - 操作的名称(可选,默认值为 None)。更多信息请参见 Name

返回

输出 Tensor,与 x 维度相同、数据类型相同(输入为 int 时,输出数据类型为 float64)。

代码示例

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])