Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jan 19, 2021
Embed
What would you like to do?
import numpy as np
a1=np.array([[20,40,30],[4,6,2],[5,10,15]])
#Soritng along last axis by default - rows
a1.sort()
print (a1)
#Output:
[[20 30 40]
[ 2 4 6]
[ 5 10 15]]
a2=np.array([[20,40,30],[4,6,2],[5,10,15]])
#Sorting by columns - first axis
a2.sort(axis=0)
print (a2)
#Output:
[[ 4 6 2]
[ 5 10 15]
[20 40 30]]
#Flatten the array and sort it
a3=np.array([[20,40,30],[4,6,2],[5,10,15]])
print (np.sort(a3,axis=None))
#Output:[ 2 4 5 6 10 15 20 30 40]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment