PyTorch torch.complex Function
PyTorch torch Reference Manual
torch.complexis a function in PyTorch used to create complex tensors from real and imaginary parts.
Function Definition
torch.complex(real, imag)
Usage Example
Example
import torch
# Create real part tensor
real = torch.tensor([1.0, 2.0, 3.0])
# Create imaginary part tensor
imag = torch.tensor([4.0, 5.0, 6.0])
# Create complex tensor from real and imaginary parts
x = torch.complex(real, imag)
print(x)
print("Real part:", x.real)
print("Imaginary part:", x.imag)
# Create real part tensor
real = torch.tensor([1.0, 2.0, 3.0])
# Create imaginary part tensor
imag = torch.tensor([4.0, 5.0, 6.0])
# Create complex tensor from real and imaginary parts
x = torch.complex(real, imag)
print(x)
print("Real part:", x.real)
print("Imaginary part:", x.imag)
Other Extensions