numpy.transpose() in Python
numpy.transpose() in Python
The numpy.transpose() permutes the dimensions of an array.
Syntax
numpy.transpose(a, axes=None)
Parameter
a : This parameter represents an input array.
axes : It is an optional parameter which by default, reverses the dimensions, otherwise permutes the axes according to the values given.
Return
This function returns the parameter ‘a’ with its axes permuted. A view is returned whenever possible.
Example 1
# Python Program explaining # numpy.transpose() function import numpy as np # making a 3x3 array val = np.array([[11, 12, 13], [14, 15, 16], [17, 18, 19]]) # value before transpose print("Before transpose: \n",+val, end ='\n\n') # value after transpose print("After transpose: \n",+val.transpose())
Output
Before transpose: [[11 12 13] [14 15 16] [17 18 19]] After transpose: [[11 14 17] [12 15 18] [13 16 19]]