|
From: | Tamas Nepusz |
Subject: | Re: [igraph] how to add vertex and edge attributes |
Date: | Tue, 30 Dec 2008 17:31:47 +0100 |
suppose I have an attribute of a node, a label with the name of the node, say "simone"Every VertexSeq object has a .select() method that can be used to select a subset of the VertexSeq. Since g.vs is the set of all vertices in the graph, you can call .select() on g.vs as follows. Suppose that your attribute is "name" and the value you are looking for is "Simone". You can do the following:how can I retrive the index of the node with label == "simone"?
g.vs.select(name="Simone") -- this returns a VertexSeq that contains ALL the vertices where the "name" attribute is "Simone". (The result is a VertexSeq and not a Vertex because theoretically there could be more than one vertex with this name). If you know that there is only one such vertex, you can type g.vs.select(name="Simone")[0] to get this single Vertex or g.vs.select(name="Simone")[0].index to get the index of this vertex.
Alternatively, you can get all the vertex names with g.vs["name"] and look for "Simone" using the .index() method of list objects: g.vs["name"].index("Simone") returns the index of the FIRST vertex whose name is "Simone".
-- Tamas
[Prev in Thread] | Current Thread | [Next in Thread] |