rustworkx.PyDiGraph.subgraph#

PyDiGraph.subgraph(nodes, /, preserve_attrs=False)#

Return a new PyDiGraph object for a subgraph of this graph

Parameters:
  • nodes (list) – 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 – If set to the True the attributes of the PyDiGraph will be copied by reference to be the attributes of the output subgraph. By default this is set to False and the attrs attribute will be None in the subgraph.

Returns:

A new PyDiGraph object representing a subgraph of this 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:

PyGraph