numpy.transpose() in Python

The Python numpy.transpose() function permutes dimensions of the array.

Basic Syntax

Following is the basic syntax for numpy.transpose() function in Python:

numpy.transpose(arr, axis=None)

And the parameters are:

ParameterDescription
arrThe input array
axis[default = None, OPTIONAL] Along the axis like 1 or 0.

Return Value

This function returns array with its axis permuted. Always a view is returned if possible.

Example’s

Following are the examples for numpy.transpose() function:

Example 1

The output for the above program is as given below:

array before transpose

[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]]

array after transpose

[[ 1 5 9]
[ 2 6 10]
[ 3 7 11]
[ 4 8 12]]

Example 2

The output for the above program is as given below:

array before transpose

[[1 2 3]
[4 5 6]]

array after transpose

[[1 4]
[2 5]
[3 6]]

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here