igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] how to create instance of igraph.Edge in Python and get to


From: Tamas Nepusz
Subject: Re: [igraph] how to create instance of igraph.Edge in Python and get to the value of 'label'-attribute of an edge
Date: Sat, 13 Dec 2008 20:00:22 +0000

Hi Stefan,

Please suggest a way to get to the value of the ‘label’-attribute.
igraph.Edge() objects are not meant to be created directly as they must always be linked to a certain igraph.Graph. Given an igraph.Graph object called ig, you can access a sequence of all the edges by ig.es (es = "edge sequence" or "edges", whichever you like better). ig.es is an object of type igraph.EdgeSeq which behaves as a plain Python list in many respects. E.g., to access the edge with index 2, you can write:

ig.es[2]

To access the "label" attribute of edge #2:

ig.es[2]["label"]

To access the "label" attribute of all edges:

ig.es["label"]

To find the ID of an edge going from vertex #2 to vertex #5 and then access its label attribute:

ig.es[ig.get_eid(2,5)]["label"]

To find the ID of an edge having a particular label:

g.es.select(label="my-label")[0].index

(The last one might need some explanation: select() is a method of igraph.EdgeSeq that filters the current edge sequence by certain criteria and returns a new edge sequence. Here we select all the edges that have "my-label" as a label, then get the first element of the resulting edge sequence, yielding an igraph.Edge object. The index attribute of igraph.Edge returns the edge index corresponding to the edge that the object represents).

Similarly, you have ig.vs to access the sequence of all vertices.

Hope this helps.

-- 
Tamas


reply via email to

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