Skip to content
Advertisement

Shuffling two 2D tensors in PyTorch and maintaining same order correlation

Is it possible to shuffle two 2D tensors in PyTorch by their rows, but maintain the same order for both? I know you can shuffle a 2D tensor by rows with the following code:

JavaScript

To elaborate: If I had 2 tensors

JavaScript

And ran them through some function/block of code to shuffle randomly but maintain correlation and produce something like the following

JavaScript

My current solution is converting to a list, using the random.shuffle() function like below.

JavaScript

This takes quite a while and was wondering if there is a better way.

Advertisement

Answer

You mean

JavaScript

?

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement