本文整理汇总了Python中igraph.Graph.es["weight"]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.es["weight"]方法的具体用法?Python Graph.es["weight"]怎么用?Python Graph.es["weight"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类igraph.Graph
的用法示例。
在下文中一共展示了Graph.es["weight"]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]
vertices = range(int(np.max(graph[:,1:3]))+1)
#print vertices
edges = graph[:,1:3].astype(int).tolist()
weights = graph[:,3].tolist()
#print edges
#print weights
g = Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
out = g.get_shortest_paths(18, to=19, weights=weights, output="vpath")
print out
out = g.get_shortest_paths(18, to=[11,19], weights=weights, output="epath")
print out
print len(g.es)
#print [e for e in g.es]
g.es["weight"] = weights
out = g.get_shortest_paths(18, to=19, weights="weight", output="vpath")
print out
out = g.get_shortest_paths(18, to=[11,19], weights="weight", output="epath")
print out
vertices = range(int(np.max(graph[:,1:3]))+2)
print vertices
print edges
edges.append([20,19])
weights.append(1.0)
g = Graph(vertex_attrs={"label":vertices}, edges=edges, directed=True)
g.es["weight"] = weights
out = g.get_shortest_paths(18, to=[11,19,20], weights=weights, output="vpath")
print out
示例2: enumerate
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]
adjList = {}
for row in rowlist:
tags = row.getAttribute("Tags")
taglist = tags.encode('utf-8').strip("><").split("><")
del tags
for i, source in enumerate(taglist):
for target in taglist[i + 1:]:
e = (source, target)
if e[0] > e[1]:
e = (target, source)
# cant add an edge if one of the verices are not made
g = Graph()
# print g
g.es["weight"] = 1.0
gen = UniqueIdGenerator()
for e in adjList:
# print e[0], e[1]
if e[0] not in gen:
sourceVertex = {}
# sourceVertex["uid"] = gen[e[0]]
sourceVertex = e[0]
g.add_vertex(sourceVertex)
# print g
if e[1] not in gen:
targetVertex = {}
# targetVertex["uid"] = gen[e[1]]
targetVertex = e[1]
示例3: Graph
# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es["weight"] [as 别名]
from igraph import Graph,plot
g = Graph([(0,1), (0,2), (0,3), (0,4), (5,2), (3,5), (5,0), (4,3), (3,6)],directed = True)
g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
g.es["weight"] = [1,5,3,7,6,2,9,5,7]
g.vs["age"] = [25, 31, 18, 47, 22, 23, 50]
g.vs["gender"] = ["f", "m", "f", "m", "f", "m", "m"]
g.es["is_formal"] = [False, False, True, True, True, False, True, False, False]
layout = g.layout_fruchterman_reingold()
g.vs["label"] = g.vs["name"]
color_dict = {"m": "blue", "f": "pink"}
g.vs["color"] = [color_dict[gender] for gender in g.vs["gender"]]
# plot(g, layout = layout, bbox = (500, 500), margin = 20)
visual_style = {}
visual_style["vertex_size"] = 20
visual_style["vertex_color"] = [color_dict[gender] for gender in g.vs["gender"]]
visual_style["vertex_label"] = g.vs["name"]
visual_style["edge_width"] = [1 + 2 * int(is_formal) for is_formal in g.es["is_formal"]]
visual_style["layout"] = layout
visual_style["bbox"] = (300, 300)
visual_style["margin"] = 20
plot(g, **visual_style)
# print g