# megengine.functional.atan2¶

atan2(y, x)[源代码]

Element-wise $$\arctan(\frac{y}{x})$$ function.

Calculates an approximation to the inverse tangent for each element $$x_i$$ of the input tensor $$x$$ with the respective element $$y_i$$ of the input tensor $$y$$.

• y – first input tensor whose elements correspond to the dividend. Should have a numeric data type.

• x – second input tensor whose elements correspond to the divisor. Must be compatible with x (see 广播机制与规则 ). Should have a numeric data type.

a tensor containing the inverse tangent of each element in $$y/x$$.

Special cases

atan2 is identical to the atan2 function of the underlying C library. The following special values are defined in the C standard:

For floating-point operands,

• if $$y$$ is +/-0 and $$x$$ is +0, the result is +/-0.

• if $$y$$ is +/-0 and $$x$$ is -0, the result is +/-π.

• if $$y$$ is greater than 0 and $$x$$ is +/-infinity, the result is +0/+π.

• if $$y$$ is less than 0 and $$x$$ is +/-infinity, the result is -0/-π.

• if $$y$$ is +/-infinityand :math:x is +infinity, tge result is +/-(π/4).

• if $$y$$ is +/-infinityand :math:x is -infinity, tge result is +/-(3π/4).

Note that +0 and -0 are distinct floating point numbers, as are +inf and -inf.

>>> F.atan2(0, 1)  # equals to atan(0)
Tensor(0.0, device=xpux:0)


Element-wise inverse tangent:

>>> y = Tensor([0, 1, -1])
>>> x = Tensor([1, 1, 1])
>>> F.atan2(y, x)
Tensor([ 0.      0.7854 -0.7854], device=xpux:0)
`