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?
Category Data Science