许多显然是 NetworkX 附带的方法似乎并未导入。例如,根据该网站,我应该能够使用:
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'
最佳答案
您正在使用的命令似乎是开发版本中的新命令。以下是有关 dag
命令的最新文档:
https://networkx.github.io/documentation/latest/reference/algorithms.dag.html
一个简单的解决方案:您可以转到找到的文档(注意网址中的“开发”)。然后将命令从那里复制并粘贴到您的版本中。您可以通过help(nx.dag)
找到您的版本。您需要从复制粘贴中删除一些显示“[doc]”的部分,您必须编辑 __all__
部分,并且您必须删除 @not_implemented_for
命令。
关于python - 缺少 python 方法 NetworkX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30330887/