简体   繁体   中英

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

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)".

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM