I have the following binary matrix (numpy array):
M = np.array([[1, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 1], [0, 0, 1, 0]])
In practice, it has two triangles on the diagonal. I would like to reverse the blocks of the matrix, so that the two triangles appear on the other diagonal, but keeping the same shape:
M = np.array([[0, 0, 1, 1], [0, 0, 1, 0], [1, 1, 0, 0], [1, 0, 0, 0]])
I have tried using a Dataframe with sort_index() and the possible combinations of axis and ascending but none of them worked.
How can I do that?
I need a general code, which works also for bigger matrices that have these triangular structures on the diagonal.

