Let’s learn how to transpose matrix in Numpy Python library.
Using a numpy transpose method
I’ll create 5 x 2 array and transpose it into a new one. You will see how easy is that with Numpy.
Of course Numpy offers dedicated function for that purpose.
import numpy as np my_array = np.arange(11, 21).reshape(5, 2) transposed_array = np.transpose(my_array) print(my_array) print(transposed_array)
I created 5 x 2 array with values 11 – 20. You can see how values got transposed in the picure above.