Shuffle a list of Tensors effectively

Hi everyone,

I have a list consisting of Tensors of size [3 x 32 x 32].

If I have a list of length, say 100 consisting of tensors t_1 ... t_100, what is the easiest way to permute the tensors in the list?

x = torch.randn(100,3,32,32)
x_perm = x[torch.randperm(100)]

You can combine the tensors using stack if they’re in a python list. You can also use something like x.index_select(0, torch.randperm(100) .


Is there a way to permute a tensor along some axis in-place, without creating a new tensor?

1 Like

Do it in numpy. They share the same storage with torch Tensors