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]])
print(x)
y =  np.swapaxes(x,0,1)
print(y)

Sample Output:

[[1 2 3]]                                                              
[[1]                                                                   
 [2]                                                                   
 [3]]

Python Code Editor:

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

Improve this sample solution and post your code through Disqus