fn

atan2

Tensor
atan2(other: Tensor | Scalar, input: Tensor)
source

Element-wise quadrant-aware inverse tangent.

Computes arctan(y/x)\arctan(y / x) while using the signs of y and x to pick the correct quadrant, returning a result in (π,π](-\pi, \pi]. Unlike arctan, this handles all four quadrants of the plane and the special cases at the axes.

Parameters

otherTensor or scalar
The x (denominator) coordinate.
inputTensor
The y (numerator) coordinate. Broadcasts against other.

Returns

Tensor

Angles in radians in the range (π,π](-\pi, \pi], with shape broadcast(input.shape, other.shape).

Notes

Definition by cases:

atan2(y,x)={arctan(y/x)x>0arctan(y/x)+πx<0,y0arctan(y/x)πx<0,y<0+π/2x=0,y>0π/2x=0,y<0\mathrm{atan2}(y, x) = \begin{cases} \arctan(y/x) & x > 0 \\ \arctan(y/x) + \pi & x < 0,\, y \ge 0 \\ \arctan(y/x) - \pi & x < 0,\, y < 0 \\ +\pi/2 & x = 0,\, y > 0 \\ -\pi/2 & x = 0,\, y < 0 \end{cases}

Useful for polar / spherical coordinate conversions. The argument order is the mathematical convention atan2(y, x).

Examples

>>> import lucid
>>> y = lucid.tensor([1.0, -1.0])
>>> x = lucid.tensor([1.0, -1.0])
>>> lucid.atan2(x, y)
Tensor([0.7854, -2.3562])