【发布时间】:2019-05-09 21:37:24
【问题描述】:
我有一个包含 250,000 个节点和 100 万条边的大图来计算它的顶点介数(没有任何权重)。我的目标是使用 python-igraph 来完成这项工作,因为它支持与其他一些包的并行计算。当我在具有 100 个顶点的相对较小的格子上比较 python-igarph 和 networkx 的结果时(见图)。我发现它们完全不同。即使对于一个有 9 个节点的 lattice,igraph 的结果都是 0,而 networkx 的结果似乎是正确的。谁能帮我解决python-igraph的这个问题?
代码如下:
from igraph import *
import networkx as nx
print("\tUse python-igraph with Vertices=100 ")
ig = Graph.Lattice([10, 10], 4, False, False, False)
bt1 = ig.betweenness(directed=False, cutoff=None,nobigint=False)
print("\tBetweenness of python-igraph:")
print(bt1)
print("\tUse networkx with Vertices=100")
G_la= nx.grid_2d_graph(10,10,periodic=False)
bt2 = nx.betweenness_centrality(G_la)
print("\tBetweenness of networkx:")
print (bt2)
在此处输入图片描述enter image description hereenter image description here
【问题讨论】:
-
能否直接提供代码(以便我们复制和粘贴)而不是图片?
-
好的,谢谢您的回复。下面是一个 10*10 格子的测试代码。
-
print("\tUse python-igraph with Vertices=100") ig = Graph.Lattice([10, 10], 4, False, False, False) bt1 = ig.betweenness(directed= False, cutoff=None,nobigint=False) print("\tBetweenness of python-igraph:") print (bt1) print("\tUse networkx with Vertices=100") G_la= nx.grid_2d_graph(10,10,periodic=假) bt2 = nx.betweenness_centrality(G_la) print("\tBetweenness of networkx:") print (bt2)
-
对不起。我只是不知道如何在评论中格式化这些代码。这是我第一次使用 Stackoverflow。
-
您可以直接编辑您的帖子。我刚刚编辑了它。你能检查我做的一切正确吗?特别是,请确保我的缩进没有任何问题。另外,您可以编辑它并添加导入语句吗?
标签: python-2.7 networkx igraph