NumPy – transpose

NumPy - transpose

NumPy – transpose. 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
1arr array to be transposed
2axesList of ints, corresponding to the dimensions. By default, the dimensions are reversed

Example Of NumPy transpose

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]]

Next Topic – Click Here

This Post Has 3 Comments

Leave a Reply