I have searched around and tried to find a solution to what seems to be a simple problem, but have come up with nothing. The problem is to sort a matrix based on its columns, progressively. So, if I have a numpy matrix like:
import numpy as np
X=np.matrix([[0,0,1,2],[0,0,1,1],[0,0,0,4],[0,0,0,3],[0,1,2,5]])
print(X)
[[0 0 1 2]
[0 0 1 1]
[0 0 0 4]
[0 0 0 3]
[0 1 2 5]]
I would like to sort it based on the first column, then the second, the third, and so on, to get a result like:
Xsorted=np.matrix([[0,0,0,3],[0,0,0,4],[0,0,1,1],[0,0,1,2],[0,1,2,5]])
print(Xsorted)
[[0,0,0,3]
[0,0,0,4]
[0,0,1,1]
[0,0,1,2]
[0,1,2,5]]
While I think it is possible to sort a matrix like this by naming the columns and all that, I would prefer to have a method for sorting that doesn't depend so much on how big the matrix is. I am using Python 3.4, if that is important.
Any help would be greatly appreciated!