Python | Numpy matrix.sort ()

NumPy | Python Methods and Functions

With the matrix.sort() method we can sort the values ​​in the matrix using the same method.

Syntax: matrix.sort ()
Return: Return a sorted matrix

Example # 1:
In this example, we can sort the elements in the matrix using matrix.sort () .

# import an important module into python

import numpy as np

 
# make a matrix with NumPy

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

  
# using the matrix.sort () method
gfg.sort ()

 

print (gfg)

Exit:

 [[1 4] [3 12]] 

Example # 2:

# import an 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] ` )

  
# using the matrix.sort () method
gfg.sort ()

 

print (gfg)

Exit:

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




Get Solution for free from DataCamp guru