PyTorch torch.atan2 function
PyTorch torch reference manual
torch.atan2 is a function in PyTorch used to compute the element-wise two-argument arctangent (arctangent2). It computes the angle from two coordinate values (y, x); the returned value is in radians, ranging over [-pi, pi].
Function definition
torch.atan2(input, other, out=None)
Parameter Description
input: Numerator tensor (y-coordinate)other: Denominator tensor (x-coordinate)out: the output tensor (optional)
Usage examples
Example
import
torch
Creating tensors
y
=
torch.
tensor
(
[
0.0
,
1.0
,
1.0
,
1.0
]
)
x
=
torch.
tensor
(
[
1.0
,
0.0
,
0.0
,
1.0
]
)
Compute the two-argument arctangent
result
=
torch.
atan2
(
y
,
x
)
(
result
)
The output is:
tensor([ 0.0000, 1.5708, -1.5708, 2.3562])