PyTorch torch.view_as_real Function
PyTorch torch Reference Manual
torch.view_as_realIt is a function in PyTorch used to convert a complex tensor view into a real tensor. It splits each complex value (real and imaginary parts) into two separate values, and the last dimension will have two elements.
Function Definition
torch.view_as_real(input)
Usage Example
Example
import torch
# Create a complex tensor
x = torch.tensor([1+2j, 3+4j, 5+6j])
# Convert to real view
y = torch.view_as_real(x)
print("Original complex tensor shape:", x.shape)
print("Real tensor shape:", y.shape)
print("Real tensor:")
print(y)
# Create a complex tensor
x = torch.tensor([1+2j, 3+4j, 5+6j])
# Convert to real view
y = torch.view_as_real(x)
print("Original complex tensor shape:", x.shape)
print("Real tensor shape:", y.shape)
print("Real tensor:")
print(y)
The output result is:
原始复数张量形状: torch.Size([3])
实数张量形状: torch.Size([3, 2])
实数张量:
tensor([[1., 2.],
[3., 4.],
[5., 6.]])
Other Extensions