Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.digraph_tensor_product#

digraph_tensor_product(first, second, /)#

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

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

  • second (PyDiGraph) – The second undirected graph object

Returns:

A new PyDiGraph 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[PyDiGraph, ProductNodeMap]

import rustworkx.generators
from rustworkx.visualization import mpl_draw

graph_1 = rustworkx.generators.directed_path_graph(2)
graph_2 = rustworkx.generators.directed_path_graph(3)
graph_product, _ = rustworkx.digraph_tensor_product(graph_1, graph_2)
mpl_draw(graph_product)
../_images/rustworkx.digraph_tensor_product_0_0.png