简体   繁体   English

igraph:当有属性时如何使用add_edges?

[英]igraph: how to use add_edges when there are attributes?

What if I need to create a graph in igraph and add a bunch of edges, but the edges have associated attributes? 如果我需要在igraph创建图形并添加一堆边缘,但边缘具有相关属性,该怎么办? It looks like .add_edges can only take a list of edges without attributes, so I've been adding them one by one with .add_edge 看起来.add_edges只能获取没有属性的边列表,所以我一直用.add_edge添加它们

graph.add_edge('A','B',weight = 20)

这里A和B是节点的名称

You can assign the attributes later; 您可以稍后分配属性; eg: 例如:

graph.es["weight"] = range(g.ecount())

This will assign weights to all the edges at once. 这将一次为所有边分配权重。 If you want to assign attributes to only a subset of the edges, index or slice the edge sequence ( g.es ) in however you want: 如果要仅将属性分配给边的子集,请根据需要对边序列( g.es )进行索引或切片:

graph.es[10:20]["weight"] = range(10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM