I'd like to progressively sort an array, like I can in excel. For example:
randomMatrix = np.asarray(
[[0, 1, 0, 1, 0, 0, 2, 0, 1, 0],
[1, 0, 0, 0, 0, 1, 0, 0, 1, 2],
[1, 1, 0, 0, 2, 0, 0, 1, 0, 0]])
I'd like to have a: "Sort by column 1. Then, sort by column2. Then sort by column3, etc. etc." like we can in excel to produce the following:
sortedMatrix = np.asarray(
[[0, 1, 2, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 2, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 2]])
How can I accomplish this? This answer recommends using lexsort, but when I do I get:
randomMatrix[np.lexsort(randomMatrix.T[::-1])]
array([[0, 1, 0, 1, 0, 0, 2, 0, 1, 0],
[1, 0, 0, 0, 0, 1, 0, 0, 1, 2],
[1, 1, 0, 0, 2, 0, 0, 1, 0, 0]])