import numpy as np
mat = np.array([[1,21,3],[5,4,2],[56,12,4]])
mat_sort = mat[mat[:,2].argsort()]
print(mat_sort)
Output:
[[ 5 4 2]
[56 12 4]
[ 1 21 3]]
If I wish to get the reverse sorting based on any column, say 3rd, what changes do i make to the code? Meaning, I wish to get:
[[56 12 4]
[ 1 21 3]
[ 5 4 2]]
P.s Yes I understand this is an easy question but I couldn't find an answer that I understood and was based for matrix and not an array or vector. TIA :)