python - 可以将边缘列表导入 igraph python

标签 python igraph

我在文本文件中有一个 Twitter 关注者列表,我想将其导入 iGraph。

这是我的列表示例

393795446 18215973
393795446 582203919
393795446 190709835
393795446 1093090866
393795446 157780872
393795446 1580109739
393795446 3301748909
393795446 1536791610
393795446 106170345
393795446 9409752

我是这样导入的

from igraph import *
twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)

但是我得到了这个错误。

---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-10-d808f2237fa8> in <module>()
----> 1 twitter_igraph = Graph.Read_Edgelist('twitter_edgelist.txt', directed=True)

InternalError: Error at type_indexededgelist.c:369: cannot add negative number of vertices, Invalid value

我不确定为什么要说负数。我检查了文件,它没有任何负数或 ID。

最佳答案

对于这种类型的文件格式,您需要使用 graph.Read_Ncol。为什么您的文件不符合典型的“edgelist”格式超出了我的范围。我自己也想过很多次。我还应该提到我从 here 中获取了答案. Tamàs 似乎是这里主要的 igraph 人。我相信他可以给出更详细的理由,说明为什么您需要使用 Ncol 而不是 Edgelist

这对我有用。

from igraph import *
twitter_igraph = Graph.Read_Ncol('twitter_edgelist.txt', directed=True)

个人插件

这是 igraph 文档可以改进的一个很好的例子。

例如:唯一带有graph.Read_Edgelist() doc的伴随文本说……

Reads an edge list from a file and creates a graph based on it. Please note that the vertex indices are zero-based.

当文件需要如何格式化时显然存在细微差别,这并没有真正告诉我任何信息。说出此函数期望文件采用的格式可以让很多人保持理智。

关于python - 可以将边缘列表导入 igraph python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32513650/

相关文章:

python - 如何找到两个字符串中都没有出现的字母?

python - 使用 Louvain 在图表中查找社区

r - 如何在R中绘制二部图

python - 向 igraph 图添加标题和图例

r - igraph:在每条边的中间添加新节点

python - 如何在 Python matplotlib 中正确缩放 3d Quiver 图?

python - 使用 networkx 绘制图形时显示背景网格(也称为单元格)

python - 按间隔中的位置对组进行计数

python - 检测矩阵中的对角线

Python igraph : delete vertices from a graph