I'd like to change the order of the column elements in
a = np.asarray(
[[0,1,1,2,2,2,2,3,3,3,4,4,4,4,4,4],
 [4,0,3,0,1,2,5,1,2,5,3,4,6,6,7,7],
 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 [0,1,0,0,1,1,1,0,0,0,1,1,0,1,0,1]]
)
based on the values of row 1-3 (0-based). My solution currently looks like this:
a[:, a.transpose()[:, 1].argsort(axis=0)]
array([[1, 2, 2, 3, 2, 3, 1, 4, 0, 4, 2, 3, 4, 4, 4, 4],
       [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1]])
which is fine, except that I'd like to also include rows 2-3 (lexicographically) in the search. Ideally, I would expect a result where the last row is [0, 1, 0, 1, ..., 0, 1] (the 2nd row which is full of zeroes should also be taken into account, but in this example it contains the same values).
