PyTorch torch.atan2 Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.atan2It is a function in PyTorch used to compute the element-wise two-dimensional arctangent (arctangent2). It calculates the angle based on two coordinate values (y, x), and the return value is in radians, ranging between [-pi, pi].

Function Definition

torch.atan2(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 tensor
y = torch.tensor([0.0, 1.0, -1.0, 1.0])
x = torch.tensor([1.0, 0.0, 0.0, -1.0])

# Compute two-dimensional arctangent
result = torch.atan2(y, x)
print(result)

The output result is:

tensor([ 0.0000,  1.5708, -1.5708,  2.3562])

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions