w3resource logo


Python Exercises

Python NumPy: Interchange two axes of an array

Python NumPy: Array Object Exercise-51 with Solution

Write a Python program to interchange two axes of an array.

Sample Solution:-

Python Code:

import numpy as np
x = np.array([[1,2,3]])
y =  np.swapaxes(x,0,1)

Sample Output:

[[1 2 3]]                                                              

Python Code Editor:

Improve this sample solution and post your code through Disqus