This function permutes the dimension of the given array. It returns a view wherever possible. The function takes the following parameters.
numpy.transpose(arr, axes)
Where,
Sr.No. | Parameter & Description |
---|---|
1 | arr The array to be transposed |
2 | axes List of ints, corresponding to the dimensions. By default, the dimensions are reversed |
import numpy as np a = np.arange(12).reshape(3,4) print 'The original array is:' print a print '\n' print 'The transposed array is:' print np.transpose(a)
Its output would be as follows −
The original array is: [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] The transposed array is: [[ 0 4 8] [ 1 5 9] [ 2 6 10] [ 3 7 11]]