PyTorch torch.imag function
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
)
(
"Imaginary part:"
,
y
)
The output is:
虚部: tensor([3., 4.])