Sort an array by row in ascending order using NumPy

In this python numpy program, we will sort an array by row in ascending order using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Sort an array by row in ascending order using np.sort().
  4. Print the output.
				
					import numpy as np
x = np.array([[6, 5],
              [10, 9],
              [8, 7]])

print("Sorting matrix by row: ")
print(np.sort(x))
				
			

Output :

				
					Sorting matrix by row: 
[[ 5  6]
 [ 9 10]
 [ 7  8]]
				
			

interchange the rows of a matrix.

sort a given array by column in ascending order.

Leave a Comment