Skip to content

Chapter two Example Three update for networkX v1.9

Jesse Bacon edited this page Mar 19, 2015 · 1 revision

#CrispyBacon
import networkx as nx
g = nx.read_edgelist(‘0.edges’)
#No longer works in networkX 1.9 worked in 1.7
#sg = nx.connected_component_subgraphs(g)[ 0 ]
sg=nx.connected_component_subgraphs(g)
b=next(sg) #works
nx.radius(b),nx.diameter(b)
center = [node for node in b.nodes() if nx.eccentricity(b, node) == nx.radius(b)]
print(center)