现在位置: 首页 > PyTorch 教程 > 正文

PyTorch torch.arctan2 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.arctan2 是 PyTorch 中用于计算逐元素二维反正切(arctangent2)的函数,与 torch.atan2 功能相同。

函数定义

torch.arctan2(input, other, out=None)

参数说明

  • input: 分子张量(y坐标)
  • other: 分母张量(x坐标)
  • out: 输出张量(可选)

使用示例

实例

import torch

# 创建张量
y = torch.tensor([0.0, 1.0, -1.0, 1.0])
x = torch.tensor([1.0, 0.0, 0.0, -1.0])

# 计算二维反正切
result = torch.arctan2(y, x)
print(result)

输出结果为:

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

Pytorch torch 参考手册 Pytorch torch 参考手册