python-igraph顶点数 [英] python-igraph number of vertices
问题描述
我使用python-igraph软件包从存储在文件中的边上创建图形。我使用Graph.Read_Edgelist来读取边缘并创建我想要的图形。当我需要获取图形中顶点的数量时,我使用Graph.vcount()函数,该函数应该返回顶点数量,这对我来说不是这种情况。对于像这样的文件:
1 2
5 300
这个函数返回301,这不是我正在寻找的!我需要它返回4,这是我的图形的实际顶点数。任何想法我可以做什么来解决这个问题?
解决方案
使用下面的函数而不是Graph.Read_Edgelist解决了我的问题:
Graph.Read_Ncol(netFile,names = True,weights =if_present,directed = True)
通过设置name = True,该函数将节点数视为名称并解决vcount问题。 $ b
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?
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.
这篇关于python-igraph顶点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!