我试图在一个非常大的图形(diggraph)上运行NetworkX的pagerank,我总是得到这个错误:
Traceback (most recent call last):
File "summarize.py", line 120, in <module>
s = summerizer().summ(q)
File "summarize.py", line 108, in summ
rank = nx.pagerank(self.G, 0.9, vector)
File "/usr/local/lib/python2.7/dist-packages/networkx/algorithms/link_analysis/pagerank_alg.py", line 93, in pagerank
W=nx.stochastic_graph(D, weight=weight)
File "/usr/local/lib/python2.7/dist-packages/networkx/generators/stochastic.py", line 42, in stochastic_graph
d[weight]=d.get(weight,1.0)/degree[u]
ZeroDivisionError: integer division or modulo by zero
我尝试删除所有零度的节点,但我仍然得到相同的错误。
如果能看到更多您的代码就太好了。因此,我们可以推测出可能的原因:
-
页面排名在无向图上工作(参见文档和前面的问题)。错误可能是由于pagerank试图将边转换为两个无向边引起的吗?
-
还有,这有区别吗?
rank = nx.pagerank(self.G.to_undirected(), 0.9, vector)