【发布时间】:2019-01-18 22:11:39
【问题描述】:
我尝试创建一个空图并添加一些从数据框中检索到的边,如下所示:
edgelist = []
for i in range(len(edges)):
edge = (int(edges.loc[i, 'source']), int(edges.loc[i, 'target']))
if edge not in edgelist:
edgelist.append(edge)
边缘列表看起来不错
[(0, 1), (0, 2), (1, 2), (0, 3), (2, 3), (2, 4), (3, 4)]
然后我创建一个空图并尝试添加边:
G = ig.Graph()
G.add_edges(edgelist)
它会抛出一个错误
Error at type_indexededgelist.c:272: cannot add edges, Invalid vertex id
顶点 ID 有什么问题?
我试图让 ids 从 1 开始,但它又抛出了这个错误。
【问题讨论】:
-
您需要先添加顶点,如文档所述。例如。
g.add_vertices(5).
标签: python python-3.x igraph