Introduction: when to use NetworkX
When to use
Unlike many other tools, it is designed to
handle data on a scale relevant to
modern
problems
Most of the core algorithms rely on
extremely fast legacy code
Highly flexible graph implementations (a
node/edge can be anything!)
When to avoid
Large-scale problems that require faster
approaches (i.e. massive networks with
100M/1B edges)
Better use of memory/threads than Python
(large objects, parallel computation)
Visualization of networks is better handled by
other professional tools
8
Introduction: a
quick example
• Use Dijkstra’s algorithm to find the shortest path in a weighted and unweighted
network.
9
>>> import networkx as nx
>>> g = nx.Graph()
>>> g.add_edge('a', 'b', weight=0.1)
>>> g.add_edge('b', 'c', weight=1.5)
>>> g.add_edge('a', 'c', weight=1.0)
>>> g.add_edge('c', 'd', weight=2.2)
Dostları ilə paylaş: