# What is the algorithm to convert an adjacency matrix to a block diagonal structure?

I'm a little at loss as to what my supervisor meant by the "hierarchical block decomposition" of a matrix, but the goal is to put a sparse symmetric adjacency matrix into a block diagonal structure to highlight the structure of the clusters present in the data.

(The data captures whether the two proteins are adjacent in a molecule: if they are, the corresponding adjacency matrix has one on their row/column, otherwise zero. I sum a few of these adjacency matrices(one for each unique molecule) and divide the result by the number of molecules(to simulate the mean).

I'm wondering how to get to the block diagonal structure from there. People over here suggest scipy's reverse CM and seaborn's heatmap should be able to do that ostensibly, but i had no luck with either so far. Should i go with SVD? What am i missng? This is what I got. Thank you kindly!

def construct_adjacency_matrix(clusters=dict, nomenclature_namespace=dict):

nbrpairs  = tree2tuplearr(clusters['nbrtree'])
dim       = len(nomenclature_namespace.items())
keys      = list(nomenclature_namespace.keys())
substrate = np.zeros((dim, dim))

for pair in nbrpairs:
if (pair[0] not in keys or pair[1] not in keys):
pass
else:
substrate[nomenclature_namespace[pair[0]],
nomenclature_namespace[pair[1]]] = 1
return substrate

def get_simplemean(targetgroup=str):
targetspath = './../clusterdata/targetgroups/{}/'.format(targetgroup)
batch       = os.listdir(targetspath)