The DiGraph class – when direction matters

So far, all of the edges in this chapter have been undirected, with no difference between an edge from A to B, and an edge from B to A. But not all relationships in life are so symmetric. If an employee-boss relationship is described by an undirected edge, it suggests that the employee can fire the boss as easily as the other way around. While possibly good for workplace morale, such arrangements aren't the norm. NetworkX supports directed edges through the DiGraph (directed graph) class.

Many of the operations already described for the Graph class translate seamlessly to the DiGraph class. Iterating through nodes and edges, accessing attributes, and visualization are all exactly the same. But there ...

Get Network Science with Python and NetworkX Quick Start Guide 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.