Torch tensor view and stride mechanics

I want my Mx2xN float tensor to become MxN complex tensor.

In this minimal example I supply the the 10x2 matrix which should become the vector [0+10j,1+11j,2+12k,...]

x = torch.stack([torch.arange(10.),torch.arange(10.,20)])
torch.view_as_complex(x.T)

gives the error RuntimeError: Tensor must have a last dimension with stride 1 because x.T.stride() is (1,10)

Trying

 x.T.as_strided(size=(2,10),stride=(10,1)).T.stride()
(1, 10)

Didn't get me any further, how do efficiently convert these?

Topic pytorch torch

Category Data Science


Found this as a hack, is this an efficient solution?

torch.complex(*x)

it unpacks the first dimension and feeds it into the real and complex dimension

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.