从g中删除子图h的最佳方法是什么?
# construct g (every vertex has 'name')
# construct h from g (subset of g, that is,
# 'name' of each vertex is taken from a vertex in g, vertices IDs will be different)
for i in xrange(0, h.vcount()):
for j in xrange(0, g.vcount()):
if h.vs[i]['name'] == g.vs[j]['name']:
g.delete_vertices(j)
我的索引超出范围。
答案 0 :(得分:1)
也许:
copy()
select()
operation,并del
(删除)符合条件的任何节点select()
和del
答案 1 :(得分:1)
我认为这可能是效率最高的:
names_to_remove = set(h.vs["name"])
vs_to_keep = g.vs.select(name_notin=names_to_remove)
g.induced_subgraph(vs_to_keep)
这里的想法是首先收集g
中要删除的集合中不的所有顶点,然后为这些顶点创建诱导子图。