Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created January 19, 2021 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/b268bc0087afe02b297f86a4a83a8781 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/b268bc0087afe02b297f86a4a83a8781 to your computer and use it in GitHub Desktop.
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