numpy.transpose() in Python
The numpy.transpose() permutes the dimensions of an array.
Syntax
1 2 3 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# 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
1 2 3 4 5 6 7 8 9 10 |
Before transpose: [[11 12 13] [14 15 16] [17 18 19]] After transpose: [[11 14 17] [12 15 18] [13 16 19]] |