This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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