【问题标题】:Format for importing edgelist into igraph in pythonpython中将edgelist导入igraph的格式
【发布时间】:2013-01-23 02:25:30
【问题描述】:

igraph 接受的用于导入 python 的 edgelist 格式是什么?包含我的加权边缘的文本文件应该是什么样的?

我之前使用过 igraph 和 R,但在我需要使用的机器上没有安装有效的 R ——所以我被困在 python 中。

我有一个类似这样的 egelist.txt:

123123, 321321, 1
222222, 333333, 2
123123, 333333, 3
222222, 321321, 4

...值采用(源、目标、权重)形式。

如何在 python 中导入它?还是我应该重新格式化我的输入?

我正在尝试

import igraph

g = igraph.Graph.Read_Edgelist()

我不知道如何设置如何告诉导入语句我的列的期望顺序是什么,以及我对文档的理解 (http://hal.elte.hu/~nepusz/development/igraph /tutorial/tutorial.html) 是假设我有 321,321 个节点在运行,而不是将“321321”作为节点的标记 ID。

【问题讨论】:

  • 看起来如果您的文件是制表符分隔而不是逗号分隔,它将是 Ncol file,使用 Graph.Read_Ncol() 读取。

标签: python social-networking igraph sna


【解决方案1】:

删除文件中的所有逗号(即仅使用空格作为分隔符),然后使用Graph.Read_Ncol。这应该可以解决问题。文件中的数字 ID 将分配给 name 顶点属性,边权重将存储在 weight 边属性中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2015-09-01
    • 2020-06-26
    相关资源
    最近更新 更多