The numpy.transpose() function is one of the most important functions in matrix multiplication. This function permutes or reserves the dimension of the given array and returns the modified array.
The numpy.transpose() function changes the row elements into column elements and the column elements into row elements. The output of this function is a modified array of the original one.
numpy.transpose(arr, axis=None)
arr: array_like
It is an ndarray. It is the source array whose elements we want to transpose. This parameter is essential and plays a vital role in numpy.transpose() function.
axis: List of ints()
If we didn't specify the axis, then by default, it reverses the dimensions otherwise permute the axis according to the given values.
This function returns a ndarray. The output array is the source array, with its axis permuted. A view is returned whenever possible.
import numpy as np a= np.arange(6).reshape((2,3)) a b=np.transpose(a) b
Output:
In the above code
In the output, the transposed array of the original array has been shown.
import numpy as np a= np.array([[1, 2], [4, 5], [7, 8]]) a b=np.transpose(a, (1,0)) b
Output:
In the above code
In the output, the transposed array of the original array has been shown.
import numpy as np a=np.ones((12,32,123,64)) b=np.transpose(a,(1,3,0,2)).shape b c=np.transpose(a,(0,3,1,2)).shape c
Output:
In the output, an array has been shown whose elements are located at the defined position in the array.