NetworkX

Previous topic

networkx.create_empty_copy

Next topic

networkx.cartesian_product

networkx.subgraph

subgraph(G, nbunch, copy=True)

Return the subgraph induced on nodes in nbunch.

Parameters:

G : graph

A NetworkX graph

nbunch : list, iterable

A container of nodes that will be iterated through once (thus it should be an iterator or be iterable). Each element of the container should be a valid node type: any hashable type except None. If nbunch is None, return all edges data in the graph. Nodes in nbunch that are not in the graph will be (quietly) ignored.

copy : bool (default True)

If True return a new graph holding the subgraph. Otherwise, the subgraph is created in the original graph by deleting nodes not in nbunch. Warning: this can destroy the graph.

Notes

subgraph(G) calls G.subgraph()