CPU tensors are compatible with numpy, you can use .numpy() to get a numpy array view on the storage.
You can inspect the memory layout using .stride(). C means highest stride first, F means lowest stride first.
For example
c = torch.randn(5,5)
print (c.stride())
returns (5,1) for me, so it would be in C order. Similarly, .continguous() makes C order.
A sightly convoluted way to get to F order would then be
cp = c.permute(list(numpy.argsort(c.stride()))).contiguous()
d = cp.permute(list(numpy.argsort(cp.stride())))
Now d.stride() will be (1,5) and (c==d).all().item() will be one.
@tom
torch.Size([4, 272, 352]) my tensor shape is this… 0,1 is one row in actual image , 2,3 is second row. But when i do reshape to get whole image , i get incorrect results compared to looping that gives correct image.