igraph-help
[Top][All Lists]
Advanced

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

[igraph] Load a random labelled network


From: Simone Caschili
Subject: [igraph] Load a random labelled network
Date: Tue, 6 May 2008 20:24:48 +0200

Hello igraphers,

I've got some issues in creating a graph from a dataset where the nodes are labeled with a random numbering. So, a short example of my dataset could be:

(20, 3); (20, 8); (3, 4); (1, 8); (12, 5); (1, 6); (6, 4); (25, 6); (5, 7); (6, 17); (4, 17)

In this case a graph of 26 vertices and 11 edges  is created. How may I load a 'correct' graph? Here the code I'm using on Python in order to load the graph from a .txt file:

######start####
import string
from igraph import *

edgelist, weights = [], []

SP_data = open("test_graph.dat", "r")

SP_data.readline()
while 1:
    line=SP_data.readline()
    if not line:
        break
    split_line=string.split(line,' ')
    edgelist.append((int(split_line[0][0:]), int(split_line[1][0:])))
      
SP_data.close()
A=len(edgelist)
g = Graph(A,edgelist)    # directed=False is the default


######end######

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?

Thank you,
Simon C.

reply via email to

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