2015-05-19 200 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命令。