|
From: | Ehecatl Antonio del R�o Chanona |
Subject: | [igraph] Adding edges by ID |
Date: | Wed, 1 Oct 2014 12:22:17 -0500 |
Hello everyone,
I am trying to add edges to a graph (through IDs), however this does not seem to work. I know how to add them by using the vertex number, however being able to add them by their ID would really make things much easier for me.
I have: >>>node_list = ['v1','v2',...] (a list of IDs) I create the graph: >>>A = Graph(len(nodes_list)) Add the IDs to the graph: >>>for vertex in range(len(nodes_list)): >>> A.vs[vertex]["id"]= nodes_list[vertex]
When I actually print these vertices “>>> print A.vs[vertex]” I get >>>igraph.Vertex(<igraph.Graph object at 0xaa6a0ac>,0,{'id': 'v1'}) >>>igraph.Vertex(<igraph.Graph object at 0xaa6a0ac>,1,{'id': 'v2'}) ... and so on
Then I create my list of edges: >>>Edges_list = [('v1', 'v2'), ('v2', 'v3')...]
When I try to add these edges to the graph >>>A.add_edges(Edges_list)
I get the error:
ValueError: no such vertex: 'v1'
Where 'v1' would be any vertex in the position of the first vertex in the first edge in the list Edges_list.
I have looked through the documentation, but I can't find what I am doing wrong. Could you give me any suggestions please? Many thanks Antonio |
[Prev in Thread] | Current Thread | [Next in Thread] |