# How to reorder/cluster adjacency matrix to maximize the interaction along the super diagonal?

I have the following code which takes a DataFrame and plot the pdist matrix.

from scipy.spatial.distance import squareform, pdist
res = pdist(df, 'euclidean')
df1 = pd.DataFrame(squareform(res), index=df.index, columns= df.index)
plt.imshow(df1)


I would like to reorder the columns such that the adjacency matrix will cluster together rows/columns with higher interactions. To make it look something like this:

• I do have spatial information on the nodes. They are embedded on $R^3$ – 0x90 Feb 15 '19 at 15:38
• @0x90 but how is adjacency connected with it? Is it more likely for the graph nodes to be connected if they are close together in $\mathbb R^3$ as opposed to farther separated nodes? – Anton Menshov Feb 15 '19 at 16:04
• I have a solution with many particles and I build its pairwise distance matrix, then I apply some threshold to convert it to binary matrix. There will edge if two nodes are close in $\mathbf R^3$ – 0x90 Feb 15 '19 at 16:06