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

PyTorch torch.imag function

PyTorch torch.imag function


PyTorch torch reference manual PyTorch torch reference manual

torch.imag A function in PyTorch for getting the imaginary part of a complex tensor.

Function definition

torch.imag(input)


Usage examples

Example

import

torch

Create a complex tensor

x

=

torch.

complex

(

torch.

tensor

(

[

1.0

,

2.0

]

)

,

torch.

tensor

(

[

3.0

,

4.0

]

)

)

Get the imaginary part

y

=

torch.

imag

(

x

)

print

(

"Imaginary part:"

,

y

)

The output is:

虚部: tensor([3., 4.])


PyTorch torch reference manual PyTorch torch reference manual