Converting networkx to igraph python but keeping the node ids of networkx graph

Viewed 315

Is there a way when converting from networkx to igraph to keep the networkx node names? As it is referred in here "Vertex names will be converted to "_nx_name" attribute and the vertices will get new ids from 0 up (as standard in igraph)".

1 Answers

igraph internally keeps the ids contiguous, so it does not allow messing with them.

You should be able to set the _nx_name as the name attribute and then delete it.

# replace name
G.vs["name"] = G.vs["_nx_name"]
del(G.vs["_nx_name"])

# check if named
G.is_named()
Related