本文整理汇总了Python中igraph.Graph.vs['pnamelst']方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.vs['pnamelst']方法的具体用法?Python Graph.vs['pnamelst']怎么用?Python Graph.vs['pnamelst']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.vs['pnamelst']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import vs['pnamelst'] [as 别名]
def merge(g1,g2):
""" merges graph g1 and graph g2 into the output graph"""
g3nslst = list(set(g1.vs['name'][:]) | set(g2.vs['name'][:]))
g3 = Graph(0,directed=True)
g3.add_vertices(g3nslst)
g3elst = []
for e in g1.get_edgelist():
g3elst.append((g1.vs['name'][e[0]],g1.vs['name'][e[1]]))
for e in g2.get_edgelist():
g3elst.append((g2.vs['name'][e[0]],g2.vs['name'][e[1]]))
g3.add_edges(g3elst)
g3.simplify()
#add attributes
g1primlst = [vn for i,vn in enumerate(g1.vs['name'][:]) if int(g1.vs['inprim'][i]) == 1]
g2primlst = [vn for i,vn in enumerate(g2.vs['name'][:]) if int(g2.vs['inprim'][i]) == 1]
g3prim = [1 if vn in g1primlst or vn in g2primlst else 0 for vn in g3.vs['name'][:]]
g3pnamelst = [[] for i in range(len(g3.vs['name'][:]))]
for i,vn1 in enumerate(g3.vs['name'][:]):
for j,vn2 in enumerate(g1.vs['name'][:]):
if vn1 == vn2:
g3pnamelst[i].extend(g1.vs['pnamelst'][j].strip().split('|'))
for j,vn2 in enumerate(g2.vs['name'][:]):
if vn1 == vn2:
g3pnamelst[i].extend(g2.vs['pnamelst'][j].strip().split('|'))
g3.vs['pnamelst'] = ['|'.join(map(str,list(set(inp)))) if inp != [] else '' for inp in g3pnamelst]
#print g1.vs['pnamelst'][:]
#print g3.vs['name'][:]
g3.vs['inprim'] = g3prim
return g3