MultiGraph.remove_edges_from#

MultiGraph.remove_edges_from(ebunch)[源代码]#

删除ebunch中指定的所有边缘。

参数
ebunch: list or container of edge tuples

列表或容器中给出的每条边都将从图表中删除。边可以是:

  • 2元组(u,v)移除u和v之间的所有边。

  • 三元组(u,v,key)键标识的边缘被删除。

  • 4个元组(u、v、key、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
[]