Utilities for creating a seriated/ordered adjacency matrix with hierarchical clustering.

author: David Saffo (

Submitted as part of the 2019 NetSI Collabathon.

netrd.utilities.cluster.clusterGraph(G, method='single', metric='euclidean', optimal_ordering=False)[source]

Create seriated adjacency matrix.

G (nx.Graph)

a networkx graph


the clustering algorithm to use for options see [1].

metric (str)

linkage method to use

optimal_ordering (bool)

if true tries to minimize the distance of succesive indexes

adjClustered (np.ndarray)

a numpy matrix with rows and columns reordered based on clustering

order (list)

a list with the new index order for rows and columns

dend (dict)

a dictionary with the hierarchy for the dendogram

link (np.ndarray)

a linkage matrix with results from clustering