Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于边权的加权无向图连通节点提取_Python_Networkx - Fatal编程技术网

Python 基于边权的加权无向图连通节点提取

Python 基于边权的加权无向图连通节点提取,python,networkx,Python,Networkx,有没有一种方法可以根据某个权重阈值从加权无向networkx图中提取连接节点?例如,获取连接节点的列表,其中权重>0.5 对于加权无向图,基本上是这样的:您可以运行您提到的连接组件算法。但首先,要么创建一个只包含所需边的新图形,要么从原始图形中删除不需要的边。比如说 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,weig

有没有一种方法可以根据某个权重阈值从加权无向networkx图中提取连接节点?例如,获取连接节点的列表,其中权重>0.5


对于加权无向图,基本上是这样的:

您可以运行您提到的连接组件算法。但首先,要么创建一个只包含所需边的新图形,要么从原始图形中删除不需要的边。比如说

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)]
[1]中的
:将networkx导入为nx
在[2]中:G=nx.Graph()
在[3]中:G.添加边(1,2,权重=1)
在[4]中:G.添加_边(2,3,重量=0.25)
在[5]中:H=nx.图([(u,v,d)表示G.边中的(u,v,d)(数据=真),如果d['weight']>0.5])
在[6]中:H.边()
Out[6]:[(1,2)]

在[7]:G.remove_edges_from([(u,v,d)for(u,v,d)在G.edges(data=True)中,如果d['weight']您可以运行您提到的连接组件算法。但是首先,您可以创建一个只包含所需边的新图形,或者从原始图形中删除不需要的边。例如

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)]
[1]中的
:将networkx导入为nx
在[2]中:G=nx.Graph()
在[3]中:G.添加边(1,2,权重=1)
在[4]中:G.添加_边(2,3,重量=0.25)
在[5]中:H=nx.图([(u,v,d)表示G.边中的(u,v,d)(数据=真),如果d['weight']>0.5])
在[6]中:H.边()
Out[6]:[(1,2)]
在[7]中:如果d['weight'],则G.从([(u,v,d)中移除(u,v,d)中的_边(data=True)