numpy.swapaxes() function with example program in python

Spread the love

numpy.swapaxes(): This function interchange two axes of an array.

Syntax: numpy.swapaxes(a, axis1, axis2)

a : array_like
Input array.

axis1 : int
First axis.

axis2 : int
Second axis.

a_swapped : ndarray
For NumPy >= 1.10.0, if a is an ndarray, then a view of a is returned; otherwise a new array is created.
For earlier NumPy versions a view of a is returned only if the order of the axes is changed, otherwise the input array is returned.

import numpy as np x = np.array([[4,5,6,7]]) b=np.swapaxes(x,0,1) print(b)





Leave a Reply

Your email address will not be published. Required fields are marked *