我正在尝试使用igraph和python尝试将节点添加到网络。我的循环遍历顶点列表。我的问题是我的代码运行缓慢且无法终止。它以StopIteration错误结束。我不确定这怎么可能。 V应该是单个顶点,并且循环应仅通过列表中的最后一个顶点并终止。
如何加快我的代码并避免用完生成器?
actor_graph.add_vertex(kevin)
kevin_node=actor_graph.vcount()-1 # should be the last node.
kevin_movies=list(full_imdb_data[full_imdb_data.nconst == kevin] ['tconst'])
actor_graph.vs['nnid'][kevin_node]=kevin
actor_graph.vs['movies'][kevin_node]="_".join(list(kevin_movies))
for i,v in enumerate(actor_graph.vs):
if v['nnid']==kevin:
continue
#import pdb; pdb.set_trace()
movies2check = list(imdb_data[imdb_data.nconst == next(v['nnid'])]['tconst'])
#full_imdb_data[full_imdb_data['category'].isin(['actor','self'])]
#import pdb; pdb.set_trace()
#list(imdb_data[imdb_data.nconst == next(v['nnid'])]['tconst'])
if movies2check is None:
continue
moviesincommon= set(kevin_movies) & set(movies2check)
if len(moviesincommon)>0:
print("added Edges ")
actor_graph.add_edge(kevin_node,v)
actor_graph.es[actor_graph.ecount()-1]['movies']="_".join(list(moviesincommon))