python - 将 python-igraph 图转换为 networkx

标签 python converters igraph networkx

最近我一直在使用 python-igraph 包,我的所有代码都基于我使用 igraph 创建的图表。现在,我需要为我的图形计算一些度量,这些度量显然是在 networkx 中实现的,而不是在 igraph 中实现的,例如 (katz_centrality_numpy, edge_betweenness_centrality, ...)。我想知道是否有办法在这两个包之间将一个图转换为另一个图,并避免再次读取文件,因为我的文件很大并且必须重复很多相同的过程。

顺便说一句,当我将 igraph 图传递给 networkx 函数时,我收到以下错误:

TypeError: 'Graph' object is not iterable

谢谢:)

最佳答案

您可以启动带边的 networkx 图:

Graph([(1,2), (3,4)])

参见 the documentation .

编辑:

这是如何使用它(感谢 nimafl 提供的代码):

graphigraph 图,我们创建 G,它是一个 networkx 图。

import networkx
A = graph.get_edgelist()
G = networkx.DiGraph(A) # In case your graph is directed
G = networkx.Graph(A) # In case you graph is undirected

关于python - 将 python-igraph 图转换为 networkx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29783828/

相关文章:

c# - Convert.FromBase64String 给出错误 "The input is not a valid Base-64 string"

c# - .NET 中的智能类型转换

python - 多重图的线图

r - igraph 对象的顶点/节点属性

python - 在设定的行范围内读取文本文件

python - Pyinstaller onedir选项-目录外的exe文件

python - 在扩展中使用 PyModule_AddIntConstant()

python - 没有写足够的行到输出文件

python - 需要转换 ASN1(x509) 的帮助

r - 如何从图中删除顶点并在其邻居之间创建边?