PyTorch torch.complex function
PyTorch torch reference manual
torch.complex is a function in PyTorch used to create a complex tensor from real and imaginary parts.
Function definition
torch.complex(real, imag)
Usage examples
Example
import
torch
Create the real-part tensor
real
=
torch.
tensor
(
[
1.0
,
2.0
,
3.0
]
)
Create the imaginary-part tensor
imag
=
torch.
tensor
(
[
4.0
,
5.0
,
6.0
]
)
Create a complex tensor from real and imaginary parts
x
=
torch.
complex
(
real
,
imag
)
(
x
)
(
"Real part:"
,
x.
real
)
(
"Imaginary part:"
,
x.
imag
)