Warning
This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.
tensor_product¶

tensor_product
(G, H)[source]¶ Return the tensor product of G and H.
The tensor product P of the graphs G and H has a node set that is the Cartesian product of the node sets, $V(P)=V(G) times V(H)$. P has an edge ((u,v),(x,y)) if and only if (u,v) is an edge in G and (x,y) is an edge in H.
Sometimes referred to as the categorical product.
Parameters: G, H: graphs
Networkx graphs.
Returns: P: NetworkX graph
The tensor product of G and H. P will be a multigraph if either G or H is a multigraph. 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 twotuple of the G and H node attributes. Missing attributes are assigned None.
For example >>> G = nx.Graph() >>> H = nx.Graph() >>> G.add_node(0,a1=True) >>> H.add_node(‘a’,a2=’Spam’) >>> P = nx.tensor_product(G,H) >>> P.nodes() [(0, ‘a’)]
Edge attributes and edge keys (for multigraphs) are also copied to the new product graph