當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python NetworkX MultiGraph.remove_edges_from用法及代碼示例

本文簡要介紹 networkx.MultiGraph.remove_edges_from 的用法。

用法:

MultiGraph.remove_edges_from(ebunch)

刪除 ebunch 中指定的所有邊。

參數

ebunch: list or container of edge tuples

列表或容器中給定的每條邊都將從圖中刪除。邊可以是:

  • 2 元組 (u, v) 刪除 u 和 v 之間的所有邊。

  • 3-tuples (u, v, key) key 標識的邊被移除。

  • 忽略數據的 4 元組 (u, v, key, data)。

注意

如果 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), (1, 2)])
>>> list(G.edges())
[(1, 2)]
>>> G.remove_edges_from([(1, 2), (1, 2)])  # silently ignore extra copy
>>> list(G.edges)  # now empty graph
[]

相關用法


注:本文由純淨天空篩選整理自networkx.org大神的英文原創作品 networkx.MultiGraph.remove_edges_from。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。