Starting node identifiers when creating a graph from the list of edges

I wonder where the Read_Edgelist function stores the original identifier from the list of edges? or under what attribute name?

Suppose I read a list of edges, for example:

1 2 2 1 1 3 

where numbers 1,2,3 are identifiers (or names) of nodes. Where does iGraph (python version) store these identifiers? I tried to extract these identifiers from the name or id attribute, but this did not work, as these two attributes should apparently be explicitly defined.

+6
source share
1 answer

Read_Edgelist assumes that the node identifiers are integers from 0 to m, where m is the maximum integer in the list edge. Thus, "there is no need to store node ids".

For example, if your edgelist.txt is 1 3 , this code

 import igraph as ig g = ig.Graph.Read_Edgelist("edgelist.txt") print g.get_adjacency() 

creates a graph with four nodes (0, 1, 2, 3) and prints

 [[0, 0, 0, 0] [0, 0, 0, 1] [0, 0, 0, 0] [0, 0, 0, 0]] 

See this answer if you do not want to create intermediate nodes.

While there is no need for a graph with consecutive node identifiers starting with 0, you can access the node identifiers using VertexSeq and Vertex :

 for v in g.vs: print v.index # node id 
+2
source

All Articles