[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] how to iterate a vertex seq to find neighbors
From: |
Simone Gabbriellini |
Subject: |
Re: [igraph] how to iterate a vertex seq to find neighbors |
Date: |
Tue, 23 Dec 2008 18:36:56 +0100 |
I am a bit confused... "weight" is an attribute of the edge, not of
the vertex...
shouldn't I need to specify the source (mynode) and the target (each
of myneighbor)?
maybe you mean g.es[myneighbor]["weight"]
but this means that python understand (how?) that the source is always mynode...
thanks,
simone
2008/12/23 Tamas Nepusz <address@hidden>:
> 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
>>
>
>
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>