igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Load a random labelled network


From: Tamas Nepusz
Subject: Re: [igraph] Load a random labelled network
Date: Tue, 6 May 2008 20:33:00 +0200

Hi Simone,

> How may I load a 'correct' graph? [...]
> I would also like that each vertex will get the same label that it has got on the .txt file.
> Is that possible through the Igraph Python version?

What about this one?

>>> from igraph import *
>>> g=load("test.txt", format="ncol")
>>> print g
Directed graph (|V| = 11, |E| = 11)
>>> g.vs["name"]
['20', '3', '8', '4', '1', '12', '5', '6', '25', '7', '17']
>>> g.get_edgelist()
[(0, 1), (0, 2), (1, 3), (4, 2), (5, 6), (4, 7), (7, 3), (8, 7), (6, 9), (7, 10), (3, 10)]

If you need an undirected graph instead of a directed one, use this:
>>> g=load("test.txt", format="ncol", directed=False)

The trick here is that the NCOL file format is practically the same that you use (but it allows edge weights in the third column of the file)

--
T.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]