PyTorch torch.complex 関数
torch.complexは、PyTorch で実部と虚部から複素テンソルを作成するための関数です。
関数定義
torch.complex(real, imag)
使用例
例
import torch
# 実部テンソルを作成
real = torch.tensor([1.0, 2.0, 3.0])
# 虚部テンソルを作成
imag = torch.tensor([4.0, 5.0, 6.0])
# 実部と虚部から複素テンソルを作成
x = torch.complex(real, imag)
print(x)
print("実部:", x.real)
print("虚部:", x.imag)
# 実部テンソルを作成
real = torch.tensor([1.0, 2.0, 3.0])
# 虚部テンソルを作成
imag = torch.tensor([4.0, 5.0, 6.0])
# 実部と虚部から複素テンソルを作成
x = torch.complex(real, imag)
print(x)
print("実部:", x.real)
print("虚部:", x.imag)
その他の拡張
Pytorch torch リファレンスマニュアル