PyTorch torch.imag Function


Pytorch torch 参考手册Pytorch torch Reference Manual

torch.imagis a function in PyTorch used to obtain the imaginary part of a complex tensor.

Function Definition

torch.imag(input)

Usage Example

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 result is:

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

Pytorch torch 参考手册Pytorch torch Reference Manual

Other Extensions