評價此頁

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