在python中将边列表导入igraph的格式 [英] Format for importing edgelist into igraph in python

查看:369
本文介绍了在python中将边列表导入igraph的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

igraph导入到python中的边列表格式是什么?包含我的加权边缘的文本文件应该是什么样?

What is the edgelist format accepted by igraph for import into python? What should the textfile that contains my weighted edges look like?

我以前将igraph与R一起使用,但是在需要使用的计算机上没有可正常工作的R安装---因此我陷入了python.

I've used igraph with R before, but don't have a working R installation on the machine I need to use---so I'm stuck in python.

我有一个egelist.txt这样的内容:

I have an egelist.txt something like this:

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

...这些值的格式为(来源,目标,重量).

...where the values are in (source, target, weight) form.

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

How would I import this in python? Or should I reformat my input?

我正在尝试

import igraph

g = igraph.Graph.Read_Edgelist()

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

I can't tell how to set how to tell the import statement what to expect the order of my columns is, and my understanding from the documentation (http://hal.elte.hu/~nepusz/development/igraph/tutorial/tutorial.html) is that this will assume I have 321,321 nodes in play, rather than taking "321321" as a tagged ID for the node.

推荐答案

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

Get rid of all the commas in your file (i.e. use only whitespace as the separator) and then use Graph.Read_Ncol. This should do the trick. The numeric IDs in your files will be assigned to the name vertex attribute and the edge weights will be stored in the weight edge attribute.

这篇关于在python中将边列表导入igraph的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆