2013-03-16 122 views
0

我試圖使用NetworkX庫的current_flow_betweenness_centrality功能,但它給了我調用時這個錯誤:蟒蛇networkx:不能使用current_flow_betweenness_centrality功能

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 unpack 

這是我使用的代碼:

import networkx as nx 

g=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。

回答

1

更新:

這是一個錯誤處理/固定在https://github.com/networkx/networkx/pull/856

原件(不正確)答案:

NetworkX節點必須是Python的 「哈希的」 對象。你的object()節點不是。 (你得到的錯誤信息不是很有幫助)。

例如這工作

import networkx as 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') 
+0

不是Object()可哈希? hash()和它們的比較工作,實際上它們可以放在set()中。 – cmant 2013-03-17 01:19:56

+0

你說得對。這裏有一些更微妙的事情,這可能是一個錯誤。 – Aric 2013-03-17 03:38:40