Python Numpy swapaxes()














































Python Numpy swapaxes()



Description
NumPy generally stands for Numerical Python and it is a general purpose array processing package.it always provides a high performance multidimensional array object. Numpy is usually for creating an array of n dimensions.

Method Name :numpy.swapaxes(arr, axis1, axis2)
Description : The function generally interchanges the two axes of an array.As the latest version after the 1.10 the view of the swapped array is being returned.

In this article, I will tell you about the parameter and its description
Parameter Name: arr
Description: The input array whose axes are to be swapped and be written as[array_like] input array.

Parameter Name: axis1
Description: An int with respect to the first axis and be written as [int] the First axis.

Parameter Name: axis2
Description: An int with respect to the second axis and be written as [int] the Second axis.

Return : The return function actually gives a view of an array which is only returned only if the order of the axes is changed and if not happen then the input array is returned. If the array is a ndarray then a view of arr is returned otherwise a new array is being created.

The first step would be to give syntax
command:
numpy.swapaxes(arr, axis1, axis2)

Example :
Code :

import numpy as np arr = np.array([[[0, 2], [4,6], [[8,7], [6, 7]]]]) abc = np.swapaxes(arr, 0, 2) print (abc)

Output


Example :
Code :

import numpy as np arr = np.array([[2, 4, 6],[3,6,9]]) abc = np.swapaxes(arr, 0, 1) print (abc)


Output



Comments