PyTorch torch.view_as_real function
PyTorch torch reference manual
torch.view_as_real A function in PyTorch for converting a view of a complex tensor into a real-valued tensor. It splits each complex value (real and imaginary parts) into two separate values, so the last dimension has two elements.
Function definition
torch.view_as_real(input)
Usage examples
Example
import
torch
Create a complex tensor
x
=
torch.
tensor
(
[
1
+2j
,
3
+4j
,
5
+6j
]
)
Convert to a real-valued view
y
=
torch.
view_as_real
(
x
)
(
"Original complex tensor shape:"
,
x.
shape
)
(
"Real tensor shape:"
,
y.
shape
)
(
"Real tensor:"
)
(
y
)
The output is:
原始复数张量形状: torch.Size([3])
实数张量形状: torch.Size([3, 2])
Real tensor:
tensor([[1., 2.],
[3., 4.],
[5., 6.]])