>>> a = np.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> a.transpose() #or a.T array([[1, 3], [2, 4]])
Here is what the above code is Doing:
1. We create a 2D array with 2 rows and 2 columns.
2. We print the array.
3. We use the .transpose() method to transpose the array.
4. We print the transposed array.
Note that the .transpose() method is equivalent to the .T attribute.