Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.view_as_real function

PyTorch torch.view_as_real function


PyTorch torch reference manual 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

)

print

(

"Original complex tensor shape:"

,

x.

shape

)

print

(

"Real tensor shape:"

,

y.

shape

)

print

(

"Real tensor:"

)

print

(

y

)

The output is:

原始复数张量形状: torch.Size([3])

实数张量形状: torch.Size([3, 2])

Real tensor:

tensor([[1., 2.],

        [3., 4.],

        [5., 6.]])


PyTorch torch reference manual PyTorch torch reference manual