MultiGraph.remove_edges_from#
- MultiGraph.remove_edges_from(ebunch)[source]#
移除 ebunch 中指定的所有边。
- 参数:
- ebunch: 边元组的列表或容器
列表或容器中给出的每条边都将从图中移除。边可以是
2元组 (u, v) 移除 u 和 v 之间的一条边。
3元组 (u, v, key) 移除由 key 标识的边。
4元组 (u, v, key, data) 其中 data 被忽略。
另请参阅
remove_edge
移除一条边
注意
如果 ebunch 中的边不在图中,将静默失败。
示例
>>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc >>> ebunch = [(1, 2), (2, 3)] >>> G.remove_edges_from(ebunch)
移除多重边
>>> G = nx.MultiGraph() >>> keys = G.add_edges_from([(1, 2), (1, 2), (1, 2)]) >>> G.remove_edges_from([(1, 2), (2, 1)]) # edges aren't directed >>> list(G.edges()) [(1, 2)] >>> G.remove_edges_from([(1, 2), (1, 2)]) # silently ignore extra copy >>> list(G.edges) # now empty graph []
当边是 2元组
(u, v)
但图中有 u 和 v 之间的多条边时,则移除最新插入的边(按插入顺序计算)。>>> G = nx.MultiGraph() >>> for key in ("x", "y", "a"): ... k = G.add_edge(0, 1, key=key) >>> G.edges(keys=True) MultiEdgeView([(0, 1, 'x'), (0, 1, 'y'), (0, 1, 'a')]) >>> G.remove_edges_from([(0, 1)]) >>> G.edges(keys=True) MultiEdgeView([(0, 1, 'x'), (0, 1, 'y')])