Transpose

Change the axises of numpy arrays.

a = np.arange(2 * 5).reshape((2, 5))
# array([[0, 1, 2, 3, 4],
#       [5, 6, 7, 8, 9]])
 
a.transpose(1, 0)
 
# array([[0, 5],
#      [1, 6],
#      [2, 7],
#      [3, 8],
#      [4, 9]])
 

transpose takes axises as arguments.

a.T

Also does the same thing. However, it only right shifts the axis and so the last axis becomes first.

Note

Transpose returns view. However, reshape on the transposed array returns a new copy. (don’t know why!)