TUTORIALAI & dataFETCHED

PyTorch torch.complex 函数

PyTorch torch.complex 函数 Pytorch torch 参考手册 torch.complex 是 PyTorch 中用于从实部和虚部创建复数张量的函数。 函数定义 torch.complex(real, imag) 使用示例 实例 [mycode4 type='python'] import torch # 创建实部张量 real = torch.tensor([1.0, ..

Updated 7/16/2026

Tutorial detail pages default to noindex.

PyTorch torch.complex 函数


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

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)

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