YouTip LogoYouTip

Pytorch Torch View_As_Complex

# PyTorch torch.view_as_complex Function * * * [![Image 3: Pytorch torch Reference Manual](https://example.com/images/up.gif) Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html) `torch.view_as_complex` is a PyTorch function used to convert a real tensor view to a complex tensor. It converts the last dimension from two real values (real and imaginary parts) to a single complex value. ### Function Definition torch.view_as_complex(input) * * * ## Usage Example ## Example import torch # Create real tensor, last dimension must have 2 elements x = torch.randn(3,2) # Convert to complex view y = torch.view_as_complex(x) print("Original real tensor shape:", x.shape) print("Complex tensor shape:", y.shape) print("Complex tensor:", y) Output result: Original real tensor shape: torch.Size([3, 2])Complex tensor shape: torch.Size()Complex tensor: tensor([ 1.2345+0.5678j, -0.3456+1.2345j, 2.3456-0.9876j]) * * * [![Image 4: Pytorch torch Reference Manual](https://example.com/images/up.gif) Pytorch torch Reference Manual](https://example.com/pytorch/pytorch-torch-ref.html)
← Pytorch Torch VmapPytorch Torch Var_Mean β†’