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