PyTorch torch.arctan2 関数
torch.arctan2は、PyTorch で要素ごとの2次元逆正接(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])
# 2次元逆正接を計算
result = torch.arctan2(y, x)
print(result)
# テンソルを作成
y = torch.tensor([0.0, 1.0, -1.0, 1.0])
x = torch.tensor([1.0, 0.0, 0.0, -1.0])
# 2次元逆正接を計算
result = torch.arctan2(y, x)
print(result)
出力結果は次のとおりです:
tensor([ 0.0000, 1.5708, -1.5708, 2.3562])
その他の拡張
Pytorch torch リファレンスマニュアル