Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.complex function

PyTorch torch.complex function


PyTorch torch reference manual 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

)

print

(

x

)

print

(

"Real part:"

,

x.

real

)

print

(

"Imaginary part:"

,

x.

imag

)


PyTorch torch reference manual PyTorch torch reference manual