Python | Numpy matrix.swapaxes ()

NumPy | Python Methods and Functions

With the matrix.swapaxes() method we can replace the axes with a matrix using the same method.

Syntax: matrix.swapaxes ()
Return: Return matrix having interchanged axes

Example # 1:
In this example we can swap the matrix axes using matrix.swapaxes () .

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[4, 1; 12, 3] ` )

  
# applying the matrix.swapaxes () method

geek = gfg.swapaxes ( 0 , 1 )

  

print (geek)

Exit :

 [[4 12] [1 3]] 

Example # 2:

# import important module into python

import numpy as np

 
# make a matrix with NumPy

gfg = np.matrix ( `[4, 1, 9; 12, 3, 1; 4, 5, 6] ` )

  
# applying the matrix.swapaxes () method

geek = gfg.swapaxes ( 1 , 1 )

 

print (geek)

Exit:

 [[4 1 9] [12 3 1] [4 5 6]] 




Get Solution for free from DataCamp guru