简体   繁体   English

根据边的权重从加权无向图提取连接节点

[英]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.

相关问题 使用networkx计算加权无向图中连接到一个节点的每个子图中的节点和边数 - Count the number of nodes and edges in each subgraph connected to one node in a weighted undirected graph with networkx 将无向加权图拆分为 k 个相等的子图,同时最小化切割边的权重 - Split undirected weighted graph into k equal subgraphs while minimizing weight of cutted edges 如何从无向图上删除一些边缘? - How to remove some edges from an undirected graph? networkx python,有向/无向图,节点和边不一致? - networkx python, directed/undirected graph, inconsistent nodes and edges? 为从 pandas 开始的无向图创建节点 - Creating nodes for an undirected graph starting from pandas 创建一个networkx加权图并找到权重最小的2个节点之间的路径 - Create a networkx weighted graph and find the path between 2 nodes with the smallest weight 在十亿个节点的无向​​图中无循环地从正好k个边的源节点中找到目标节点的算法/方法 - Algorithm/Approach to find destination node from source node of exactly k edges in undirected graph of billion nodes without cycle 有没有什么方法可以将对称权重矩阵转换为无向权图而无需循环? - Are there any ways to convert a symmetric weight matrix into undirected weighted graph without looping? Python:从共生矩阵创建无向加权图 - Python: creating undirected weighted graph from a co-occurrence matrix 从igraph中的txt文件导入/创建加权和无向图 - Import / create a weighted and undirected graph from a txt file in igraph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM