PyTorch torch.arctan2 Function
Pytorch torch Reference Manual
torch.arctan2is a function in PyTorch used to compute the element-wise two-argument arctangent (arctangent2), with the sametorch.atan2functionality.
Function Definition
torch.arctan2(input, other, out=None)
Parameter Description
input: numerator tensor (y-coordinate)other: denominator tensor (x-coordinate)out: output tensor (optional)
Usage Example
Example
import torch
# Create 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.arctan2(y, x)
print(result)
# Create 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.arctan2(y, x)
print(result)
The output result is:
tensor([ 0.0000, 1.5708, -1.5708, 2.3562])
Other Extensions