compose_all#
- compose_all(graphs)[source]#
Returns the composition of all graphs.
Composition is the simple union of the node sets and edge sets. The node sets of the supplied graphs need not be disjoint.
- Parameters:
- graphsiterable
Iterable of NetworkX graphs
- Returns:
- CA graph with the same type as the first graph in list
- Raises:
- ValueError
If
graphs
is an empty list.- NetworkXError
In case of mixed type graphs, like MultiGraph and Graph, or directed and undirected graphs.
Notes
For operating on mixed type graphs, they should be converted to the same type.
Graph, edge, and node attributes are propagated to the union graph. If a graph attribute is present in multiple graphs, then the value from the last graph in the list with that attribute is used.
Examples
>>> G1 = nx.Graph([(1, 2), (2, 3)]) >>> G2 = nx.Graph([(3, 4), (5, 6)]) >>> C = nx.compose_all([G1, G2]) >>> list(C.nodes()) [1, 2, 3, 4, 5, 6] >>> list(C.edges()) [(1, 2), (2, 3), (3, 4), (5, 6)]