O'Reilly logo

Complex Network Analysis in Python by Dmitry Zinoviev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Work with Edge Lists and Node Dictionaries

You do not have to mess with matrices, NumPy, and Pandas to bulk move data between your code and NetworkX networks. You can use edge lists and node dictionaries.

Edge Lists

An edge list is a list of 3-tuples containing the start node, end node, and a dictionary of edge attributes for each edge. You can obtain it from an existing network by calling nx.to_edgelist or construct it yourself and feed as the parameter to nx.from_edgelist to produce a new network.

 edges = nx.to_edgelist(G)
 F = nx.from_edgelist(edges)
 print​(F.edges(data=True))
<= [('Born', 'Married', {'weight': 1}), ('Married', 'Elected Rep',
  {'weight': 1}), ('Elected Pres', 'Died', {'weight': 1}),
  ('Died', 'Born', {'weight': 0.1}), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required