本文介绍了python networkx:不能使用current_flow_betweenness_centrality函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试使用NetworkX库的current_flow_betweenness_centrality函数,但调用时出现此错误: 回溯(最近一次调用最后):在< module>文件中,第47行的文件D:\ IVV \pcg\procsator\__init __。py el_val_rel = graph.elements_values(元素,conn_graph,米)文件 d:\IVV\pcg\procsator\graph.py,第46行,在elements_values conn_val = metric_func(克)文件 C:\Python27\lib\site-packages\\\etworkx\algorithms\centrality\current_flow_betweenness.py,线路233,在current_flow_betweenness_centrality 求解=解算器):文件C: \Python27\lib\site-packages\\\etworkx\algorithms\centrality\flow_matrix.py,第15行,在flow_matrix_row dtype = dtype,format ='csc')文件C: \Python27\lib\site-packages\\\etworkx\algorithms\centrality\flow_matrix.py 线路135,在laplacian_sparse_matrix D型细胞= D型细胞,格式=格式)文件 C:\ Python27 \lib\site-packages\\\etworkx\convert.py,第790行,在to_scipy_sparse_matrix 中,u,v,d在G.edges_iter(nodelist,data = True)中ValueError:需要超过0值为解压缩 这是我使用的代码: 导入networkx为nx $ b $ = nx.Graph()a = object()b = object()c = object()d = object() g.add_edge(a,b,{'distance':4.0}) g.add_edge(a,c,{'distance': 1.5}) g.add_edge(b,c,{'distance':2.2}) g.add_edge(c,d,{'distance':2.6}) result = nx .current_flow_betweenness_centrality(g,weight ='distance') 我错在哪里? 在Windows 7 x64上使用Python 2.7和3.3进行NetworkX 1.7测试。 > 这是一个在 https:/ /github.com/networkx/networkx/pull/856 原文(不正确)答案: 例如,这可以工作 导入networkx为nx g = nx.Graph()a = 1 b = 2 c = 3 d = 4 g.add_edge(a,b,{'distance':4.0}) g.add_edge(a,c,{'distance':1.5}) g.add_edge(b,c, {'distance':2.2}) g.add_edge(c,d,{'distance':2.6}) result = nx.current_flow_betweenness_centrality(g,weight ='distance') I'm trying to use the current_flow_betweenness_centrality function of the NetworkX library, but it gives me this error when called:Traceback (most recent call last): File "D:\IVV\pcg\procsator\__init__.py", line 47, in <module> el_val_rel = graph.elements_values(elements, conn_graph, m) File "D:\IVV\pcg\procsator\graph.py", line 46, in elements_values conn_val = metric_func(g) File "C:\Python27\lib\site-packages\networkx\algorithms\centrality\current_flow_betweenness.py", line 233, in current_flow_betweenness_centrality solver=solver): File "C:\Python27\lib\site-packages\networkx\algorithms\centrality\flow_matrix.py", line 15, in flow_matrix_row dtype=dtype, format='csc') File "C:\Python27\lib\site-packages\networkx\algorithms\centrality\flow_matrix.py", line 135, in laplacian_sparse_matrix dtype=dtype, format=format) File "C:\Python27\lib\site-packages\networkx\convert.py", line 790, in to_scipy_sparse_matrix for u,v,d in G.edges_iter(nodelist, data=True) ValueError: need more than 0 values to unpackThis is the code I'm using:import networkx as nxg=nx.Graph()a=object()b=object()c=object()d=object()g.add_edge(a,b,{'distance': 4.0})g.add_edge(a,c,{'distance': 1.5})g.add_edge(b,c,{'distance': 2.2})g.add_edge(c,d,{'distance': 2.6})result = nx.current_flow_betweenness_centrality(g, weight='distance')Where am I wrong?Tried with NetworkX 1.7 with both Python 2.7 and 3.3, on Windows 7 x64. 解决方案 Update:This is a bug addressed/fixed in https://github.com/networkx/networkx/pull/856Original (incorrect) answer:NetworkX nodes must be Python "hashable" objects. Your object() nodes are not. (The error message you got isn't very helpful).For example this worksimport networkx as nxg=nx.Graph()a=1b=2c=3d=4g.add_edge(a,b,{'distance': 4.0})g.add_edge(a,c,{'distance': 1.5})g.add_edge(b,c,{'distance': 2.2})g.add_edge(c,d,{'distance': 2.6})result = nx.current_flow_betweenness_centrality(g, weight='distance') 这篇关于python networkx:不能使用current_flow_betweenness_centrality函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 20:18