rustworkx.graph_tensor_product#

graph_tensor_product(first, second, /)#

Return a new PyGraph by forming the tensor product from two input PyGraph objects

Parameters:
  • first (PyGraph) – The first undirected graph object

  • second (PyGraph) – The second undirected graph object

Returns:

A new PyGraph object that is the tensor product of first and second. A read-only dictionary of the product of nodes is also returned. The keys are a tuple where the first element is a node of the first graph and the second element is a node of the second graph, and the values are the map of those elements to node indices in the product graph. For example:

{
    (0, 0): 0,
    (0, 1): 1,
}

Return type:

Tuple[PyGraph, ProductNodeMap]

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph_1 = rustworkx.generators.path_graph(2)
graph_2 = rustworkx.generators.path_graph(3)
graph_product, _ = rustworkx.graph_tensor_product(graph_1, graph_2)
mpl_draw(graph_product)
../_images/rustworkx.graph_tensor_product_0_0.png