捷徑

torch.complex

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

建構一個複數張量,其實部等於 real,虛部等於 imag

參數
  • real (Tensor) – 複數張量的實部。必須是 half、float 或 double。

  • imag (Tensor) – 複數張量的虛部。必須與 real 具有相同的 dtype。

關鍵字參數

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

文件

存取 PyTorch 的全面開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並取得您問題的解答

檢視資源