def create_hc(G):
 path_length = nx.all_pairs_shortest_path_length(G)
 distances = numpy.zeros((len(G), len(G)))
 for (u, p) in path_length.items():
  for (v, d) in p.items():
   distances[u][v] = d
 Y = distance.squareform(distances)
 Z = hierarchy.complete(Y)
 membership = list(hierarchy.fcluster(Z, t=1.15))
 partition = defaultdict(list)
 for (n, p) in zip(list(range(len(G))), membership):
  partition[p].append(n)
 return list(partition.values())

def create_hc ( G ) : path_length = nx . all_pairs_shortest_path_length ( G ) distances = numpy . zeros ( ( len ( G ) , len ( G ) ) ) for ( u , p ) in path_length . items ( ) : for ( v , d ) in p . items ( ) : distances [ u ] [ v ] = d Y = distance . squareform ( distances ) Z = hierarchy . complete ( Y ) membership = list ( hierarchy . fcluster ( Z , t = 1.15 ) ) partition = defaultdict ( list ) for ( n , p ) in zip ( list ( range ( len ( G ) ) ) , membership ) : partition [ p ] . append ( n ) return list ( partition . values ( ) )
creates hierarchical cluster of graph g from distance matrix .