[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Reading Symbolic Adjacency
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] Reading Symbolic Adjacency |
Date: |
Wed, 21 Apr 2010 10:47:15 +0100 |
> My only question before trying to implement your suggestion is the following:
> what if you already have a numpy array containing the data in the file
> "your_graph.txt"?
You can use the second code snippet in my earlier email with a small
modification; instead of the following:
for line in f:
source, target = line.strip().split()
...you can do this:
for row in your_numpy_array:
source, target = row
You can also make use of Graph.DictList and a little bit of iterator trickery:
def array_to_dict_iter(array):
for row in array:
yield dict(source=row[0], target=row[1])
g = Graph.DictList(vertices=None, edges=array_to_dict_iter(your_numpy_array))
For more information, see
http://igraph.sourceforge.net/doc/python/igraph.Graph-class.html#DictList
--
Tamas