How do I transpose the first 2 dimensions of a 3D array ‘matrix?
matrix = np.random.rand(2,3,4)
In the third dimensions I want to swap ‘rows’ with ‘columns’, preferably without a loop.
You can use the
matrix = matrix.transpose(1, 0, 2)
means swap the first and the second axis.
Answered By – LukasNeugebauer
Answer Checked By – Clifford M. (BugsFixing Volunteer)