Don’t do this, it is not a real random transformation!
indeed:
The number of possible transformations for a N x N square matrix: (N*N)!
Or, with two permutations of the lines and the columns as you do, there are (N!)*(N!) possible transformation
And (N*N)! is far higher than (N!)*(N!) when N is high…
with you code, the matrix
t=torch.tensor([[1,2],[3,4]])

will never be randomized into
t=torch.tensor([[1,4],[2,3]])

Use the code of @ptrblck with the view, it is a good one