2015-05-19 90 views
1

許多顯然與NetworkX一起使用的方法似乎並未導入。例如,根據該網站,我應該能夠使用:缺少python方法NetworkX

http://networkx.github.io/documentation/development/reference/generated/networkx.algorithms.dag.transitive_closure.html

transitive_closure()方法。

但是當我運行python.py文件,

import networkx as nx 

G = nx.DiGraph() 

G.add_edges_from([ 
    ('a', 'c'), 
    ('b', 'c'), 
    ('c', 'd'), 
]) 

C = nx.transitive_closure(G) 

我得到的錯誤

C = nx.transitive_closure(G) 
AttributeError: 'module' object has no attribute 'transitive_closure' 

回答

1

你使用似乎是在開發新版本的命令。下面是對dag命令當前文檔:

https://networkx.github.io/documentation/latest/reference/algorithms.dag.html

一個簡單的解決方案:你可以去,你發現的文檔(注意在URL中的「發展」)。然後從那裏複製並粘貼命令到您的版本中。你可以在help(nx.dag)找到你的版本。您需要從複製粘貼的「[doc]」中刪除一些部分,您必須編輯__all__部分,並且您必須刪除@not_implemented_for命令。