Construct a Simple Network with NetworkX
A NetworkX project begins with importing module networkx (usually under the name nx).
| import networkx as nx |
Create a Graph
A NetworkX network is a collection of edges and labeled nodes. The library allows you to use any hashable Python data as a node label (different labels within the same graph may belong to different data types). To create a new network graph, you must choose an appropriate graph type and call the respective constructor; pass either no parameters (for an empty graph) or a list of edges as node pairs (lists or tuples). NetworkX supports four graph types:
-
Undirected graphs consist only of undirected edges—edges that can be traversed in either direction so that an edge from ...
Get Complex Network Analysis in Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.