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.graph_cartesian_product#
- graph_cartesian_product(first, second, /)#
Return a new PyGraph by forming the cartesian product from two input PyGraph objects
- Parameters:
- Returns:
A new PyGraph object that is the cartesian product of
first
andsecond
. It’s worth noting the weight/data payload objects are passed by reference fromfirst
andsecond
to this new object. 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_cartesian_product(graph_1, graph_2) mpl_draw(graph_product)