tensors.
Transition from the old representation
Users who currently worked around the lack of complex tensors with
real tensors of shape (..., 2) can easily to switch using the complex
tensors in their code using "torch.view_as_complex()" and
"torch.view_as_real()". Note that these functions donât perform any
copy and return a view of the input tensor.



x = torch.randn(3, 2)
x
   tensor([[ 0.6125, -0.1681],
        [-0.3773,  1.3487],
        [-0.0861, -0.7981]])
y = torch.view_as_complex(x)
y
   tensor([ 0.6125-0.1681j, -0.3773+1.3487j, -0.0861-0.7981j])
torch.view_as_real(y)
   tensor([[ 0.6125, -0.1681],
        [-0.3773,  1.3487],
        [-0.0861, -0.7981]])



Accessing real and imag
The real and imaginary values of a complex tensor can be accessed
using the "real" and "imag".
Note:
Accessing real and imag attributes doesn't allocate any memory,