[Top][All Lists]

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

Re: [igraph] ID's for nodes/vertices

From: Tamas Nepusz
Subject: Re: [igraph] ID's for nodes/vertices
Date: Mon, 11 Jul 2011 15:07:34 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10

> Hi, when importing graph files do vertices/nodes keep there original
> ID or are nodes reassigned a new int value?
No, they do not keep their original IDs because igraph requires that node
IDs start from zero and are continuous. When you have a graph with n
vertices, the vertex IDs will always go from 0 to n-1.

> If so what is the simplest method to find the new ID value?
The original IDs are stored in the "name" attribute (at least for the NCOL
and LGL formats), which you can query as:


assuming that your graph is in the variable "g". (g.vs represents the entire
vertex sequence of the graph, and it can either be indexed as a list to gain
access to the attributes of an individual vertex, or as a dictionary to
query some attribute for all the nodes in the graph).

So, to find the node which has the original name 290000, you can simply do this:

node_index = g.vs["name"].index("290000")

(Note that names are always strings). If you intend to do many name lookups,
you may want to construct a dictionary that maps names to IDs:

names_to_ids = dict((v, k) for k, v in enumerate(g.vs["name"]))


reply via email to

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