簡體   English   中英

根據邊的權重從加權無向圖提取連接節點

[英]extracting connected nodes from weighted undirected graph based on the weight of the edges

有沒有一種方法可以基於一些權重閾值從加權無向networkx圖中提取連接的節點? 例如,獲取連接節點的列表,其中權重> 0.5。

因此,對於加權無向圖,基本上是這樣的: http : //networkx.lanl.gov/reference/genic/networkx.algorithms.components.connected.connected_components.html#networkx.algorithms.components.connected.connected_components

您可以運行您提到的連接組件算法。 但是,首先要么僅使用所需的邊創建一個新圖形,要么從原始圖形中刪除不需要的邊。 例如

In [1]: import networkx as nx

In [2]: G = nx.Graph()

In [3]: G.add_edge(1,2,weight=1)

In [4]: G.add_edge(2,3,weight=0.25)

In [5]: H = nx.Graph([(u,v,d) for (u,v,d) in  G.edges(data=True) if d['weight']>0.5])

In [6]: H.edges()
Out[6]: [(1, 2)]

In [7]: G.remove_edges_from([(u,v,d) for (u,v,d) in  G.edges(data=True) if d['weight']<0.5])

In [8]: G.edges()
Out[8]: [(1, 2)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM