MultiGraph.edge_subgraph#

MultiGraph.edge_subgraph(edges)#

返回由指定边诱导的子图。

诱导子图包含 edges 每个节点都与这些边中的任何一条相连。

参数
edges可迭代的

此图中的边的可迭代。

返回
G

具有相同边属性的该图的边导出子图。

笔记

返回的子图视图中的图、边和节点属性是对原始图中相应属性的引用。该视图是只读的。

要创建具有自己的边或节点属性副本的子图的完整图形版本,请使用:

G.edge_subgraph(edges).copy()

实例

>>> 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)]