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.PyDiGraph.subgraph_with_nodemap#
- PyDiGraph.subgraph_with_nodemap(nodes, /, preserve_attrs=False)#
Return a new PyDiGraph object for a subgraph of this graph and a NodeMap object that maps the nodes of the subgraph to the nodes of the original graph.
Note
This method is identical to
subgraph()
but includes a NodeMap object that maps the nodes of the subgraph to the nodes of the original graph.- Parameters:
nodes (list[int]) – A list of node indices to generate the subgraph from. If a node index is included that is not present in the graph it will silently be ignored.
preserve_attrs (bool) – If set to
True
the attributes of the PyDiGraph will be copied by reference to be the attributes of the output subgraph. By default this is set toFalse
and theattrs
attribute will beNone
in the subgraph.
- Returns:
A tuple containing a new PyDiGraph object representing a subgraph of this graph and a NodeMap object that maps the nodes of the subgraph to the nodes of the original graph. It is worth noting that node and edge weight/data payloads are passed by reference so if you update (not replace) an object used as the weight in graph or the subgraph it will also be updated in the other.
- Return type: