lexicographic_product#
- lexicographic_product(G, H)[source]#
Returns the lexicographic product of G and H.
The lexicographical product
of the graphs and has a node set that is the Cartesian product of the node sets, . has an edge if and only if is an edge in or and is an edge in .- Parameters:
- G, H: graphs
Networkx graphs.
- Returns:
- P: NetworkX graph
The Cartesian product of G and H. P will be a multi-graph if either G or H is a multi-graph. Will be a directed if G and H are directed, and undirected if G and H are undirected.
- Raises:
- NetworkXError
If G and H are not both directed or both undirected.
Notes
Node attributes in P are two-tuple of the G and H node attributes. Missing attributes are assigned None.
Examples
>>> G = nx.Graph() >>> H = nx.Graph() >>> G.add_node(0, a1=True) >>> H.add_node("a", a2="Spam") >>> P = nx.lexicographic_product(G, H) >>> list(P) [(0, 'a')]
Edge attributes and edge keys (for multigraphs) are also copied to the new product graph