评价此页

torch.complex#

torch.complex(real, imag, *, out=None) Tensor#

构造一个复数张量,其实部等于 real,虚部等于 imag

参数
  • real (Tensor) – 复数张量的实部。必须为 half、float 或 double。

  • imag (Tensor) – 复数张量的虚部。必须与 real 的数据类型相同。

关键字参数

out (Tensor) – 如果输入为 torch.float32,则必须为 torch.complex64。如果输入为 torch.float64,则必须为 torch.complex128

示例

>>> real = torch.tensor([1, 2], dtype=torch.float32)
>>> imag = torch.tensor([3, 4], dtype=torch.float32)
>>> z = torch.complex(real, imag)
>>> z
tensor([(1.+3.j), (2.+4.j)])
>>> z.dtype
torch.complex64