Sort an array by column in ascending order using NumPy.

In this python numpy program, we will sort an array by column 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 column in ascending order using np.sort() and set the axis equal to 0.
  4. Print the output.
				
					import numpy as np
x = np.array([[6, 5],
              [10, 9],
              [8, 7]])

print("Sorting matrix by column: ")
print(np.sort(x,axis=0))
				
			

Output :

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

sort an array by row in ascending order.

extract all numbers from a given array that are greater than a specified number.

Leave a Comment