#

Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

#

networkx.MultiGraph.edge_subgraph

MultiGraph.edge_subgraph(edges)

Returns the subgraph induced by the specified edges.

The induced subgraph contains each edge in edges and each node incident to any one of those edges.

Parameters

edges (iterable) – An iterable of edges in this graph.

Returns

G – An edge-induced subgraph of this graph with the same edge attributes.

Return type

Graph

Notes

The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.

To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:

>>> G.edge_subgraph(edges).copy()  

Examples

>>> G = nx.path_graph(5)
>>> H = G.edge_subgraph([(0, 1), (3, 4)])
>>> list(H.nodes)
[0, 1, 3, 4]
>>> list(H.edges)
[(0, 1), (3, 4)]