python-igraph number of vertices

柔情痞子 提交于 2019-12-10 20:50:03

问题


I am using python-igraph package to create a graph from my edges stored in a file. I use Graph.Read_Edgelist to read the edges and create my desired graph. When I need to get the number of vertices in my graph I use the Graph.vcount() function which is supposed to return number of vertices which is not the case for me. For a file like this:

1 2
5 300

This function returns 301 which is not what I am looking for ! I need it to return 4 which is the actual number of vertices of my graph. Any idea what I can do to solve this problem?


回答1:


Solved my problem using the following function instead of Graph.Read_Edgelist:

Graph.Read_Ncol(netFile, names=True, weights="if_present", directed=True)

By setting "name=True" the function considers the nodes numbers as their name and solves the vcount problem.



来源:https://stackoverflow.com/questions/29268262/python-igraph-number-of-vertices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!