|
From: | Tamas Nepusz |
Subject: | Re: [igraph] how to iterate a vertex seq to find neighbors |
Date: | Tue, 23 Dec 2008 15:31:17 +0100 |
Hi Simone,
I need to access the weight value of the link that connects mynode and myneighbor: for mynode in g.vs:
for mynode in g.vs: neighborhood = g.neighbors(mynode.index, type="OUT") for myneighbor in neighborhood: myExperience.append(g.vs[myneighbor]["weight"])Note that you'll have to call g.neighbors() instead of igraph.GraphBase.neighbors() in the second line -- the former is necessary for Python to know which graph object you are working with. igraph.GraphBase.neighbors() is a so-called "unbound" method instance -- it is not bound to a specific graph object, therefore if you use igraph.GraphBase.neighbors(), the first argument must always be the graph object you want to bind the method to. (This is somewhat awkward in Python, that's why you should simply call g.neighbors() as it implicitly specifies the graph object you are working with).
Note also that g.vs behaves somewhat like a list: you can index it by integers and the result is always a Vertex object with the given index. That's why you can use g.vs[vertexindex]["weight"] to get the weight attribute of a specific vertex. Think of g.vs as a list of Vertex objects.
-- Tamas
[Prev in Thread] | Current Thread | [Next in Thread] |