本文整理匯總了Python中graph_tool.Graph.edge_properties["weights"]方法的典型用法代碼示例。如果您正苦於以下問題:Python Graph.edge_properties["weights"]方法的具體用法?Python Graph.edge_properties["weights"]怎麽用?Python Graph.edge_properties["weights"]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.edge_properties["weights"]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_graph
# 需要導入模塊: from graph_tool import Graph [as 別名]
# 或者: from graph_tool.Graph import edge_properties["weights"] [as 別名]
def load_graph(infile):
inmatrix = np.loadtxt(infile, dtype=np.dtype('uint32'), delimiter=" ")
numv = np.amax(inmatrix[:,0:2])
#print numv, inmatrix[:,0:2]
g = Graph(directed=False)
edge_weights = g.new_edge_property("double")
g.edge_properties["weights"] = edge_weights
vlist = list(g.add_vertex(numv))
for i in inmatrix:
edge = g.add_edge(vlist[i[0]-1], vlist[i[1]-1]) # need to convert from 1-based index in file to 0-based
edge_weights[edge] = i[2]
remove_parallel_edges(g)
return g