numpy.sort () in Python



Parameters :

arr: Array to be sorted.
axis: Axis along which we need array to be started.
order: This argument specifies which fields to compare first.
kind: [`quicksort` {default }, `mergesort`, `heapsort`] Sorting algorithm.

Return:

 Sorted Array 

# importing libraries

import numpy as np

 
# sort by first axis

a = np.array ([[ 12 , 15 ], [ 10 , 1 ]])

arr1 = np.sort (a, axis = 0

print ( "Along first axis:" , arr1) 

  

  
# sort by last axis

a = np.array ([[ 10 , 15 ], [ 12 , 1 ]])

arr2 = np.sort (a, axis = - 1

print ( "Along first axis:" , arr2)

 

 

a = np.array ([[ 12 , 15 ], [ 10 , 1 ]])

arr1 = np.sort (a, axis = None

print ( "Along none axis:" , arr1)

Output:

 Along first axis: [[10 1] [12 15]] Along first axis: [[10 15] [1 12]] Along none axis: [1 10 12 15]