[英]extracting connected nodes from weighted undirected graph based on the weight of the edges
Is there a way to extract connected nodes from a weighted undirected networkx graph based on some weight threshold? 有没有一种方法可以基于一些权重阈值从加权无向networkx图中提取连接的节点? For example get lists of connected nodes, where weight > 0.5.
例如,获取连接节点的列表,其中权重> 0.5。
So basically something like this for weighted undirected graphs: http://networkx.lanl.gov/reference/generated/networkx.algorithms.components.connected.connected_components.html#networkx.algorithms.components.connected.connected_components 因此,对于加权无向图,基本上是这样的: http : //networkx.lanl.gov/reference/genic/networkx.algorithms.components.connected.connected_components.html#networkx.algorithms.components.connected.connected_components
You can run the connected components algorithm that you mention. 您可以运行您提到的连接组件算法。 But first either create a new graph with only the edges you want, or remove the edges you don't want from the original graph.
但是,首先要么仅使用所需的边创建一个新图形,要么从原始图形中删除不需要的边。 For example
例如
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.