networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturnsBackRef
tensor_product(G, H)

The tensor product $P$ of the graphs $G$ and $H$ has a node set that is the tensor 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,x)$ is an edge in $G$ and $(v,y)$ is an edge in $H$.

Tensor product is sometimes also referred to as the categorical product, direct product, cardinal product or conjunction.

Notes

Node attributes in P are two-tuple of the G and H node attributes. Missing attributes are assigned None.

Parameters

G, H: graphs :

Networkx graphs.

Raises

NetworkXError

If G and H are not both directed or both undirected.

Returns

P: NetworkX graph

The tensor 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.

Returns the tensor product of G and H.

Examples

>>> G = nx.Graph()
... H = nx.Graph()
... G.add_node(0, a1=True)
... H.add_node("a", a2="Spam")
... P = nx.tensor_product(G, H)
... list(P) [(0, 'a')]

Edge attributes and edge keys (for multigraphs) are also copied to the new product graph

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.operators.product.tensor_product

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/operators/product.py#124
type: <class 'function'>
Commit: