I wonder, where does the function Read_Edgelist store the original id's from the the edge list? or under which attribute name?
Assume that I am reading an edge list like:
1 2
2 1
1 3
where the numbers 1,2,3
are the ids (or names) of the nodes. Where does the iGraph (python version) stores these ids?
I tried retrieving these Ids from the attribute name
or id
but it did not work, as those two attributes, seemingly, must be explicitly defined.
Read_Edgelist
assumes the node ids are the consecutive integers from 0 to m, where m is the maximum integer in the edge list. So 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 "intermediate" nodes to be created.
While the following is unnecessary for a graph with consecutive node ids starting with 0, one could access the node ids using VertexSeq
and Vertex
:
for v in g.vs:
print v.index # node id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With