Randomly shuffling torch tensor

Viewed 2553

I have a tensor of batch size of 64. Each sample in the batch is of shape [4, 300]. So, shape of my batch is [64, 4, 300]. I want to randomly shuffle the elements of the batch. In other words, I want to shuffle all 64 [4, 300] tensors. How can I do this? The resulting tensor will obviously be of shape [64, 4, 300], but all the 64 rows of shape [4, 300], will be ordered differently.

1 Answers
indexes = torch.randperm(data.shape[0])
data = data[indexes]
Related