torch.complex¶
- torch.complex(real, imag, *, out=None) Tensor ¶
构造一个复数张量,其真实部分等于
real
,虚数部分等于imag
。- 参数
- 关键字参数
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