a = np.array([[1.0, 0.5, 0.5, 0.0], [0.5, 0.5, 1.0, 0.0], [0.0, 1.0, 0.0, 
    0.5], [0.0, 0.5, 0.5, 1.0]])
np.array(sorted(a, cmp=lambda x, y: list(x).index(1) - list(y).index(1)))
Sort a numpy matrix based on its diagonal