图形工具:如何访问复制图形的属性

Graph-tool: How to access properties of a copied graph

我创建了图 g 的过滤图,并想将其用作新图。据我所知,这些属性也被复制了,但我如何访问它们?如果我使用 "weight" 它将是 g 的 属性 映射而不是 sub.

weight = g.new_edge_property('float')
vfilt = g.new_vertex_property('bool')
...
old_sub = gt.GraphView(g, vfilt)
sub = gt.Graph(old_sub, directed=False, prune=True)

如果属性没有复制到sub,怎么能做到呢。由于新图的顶点数不同,因此顶点的索引发生了变化。

非常感谢

在复制之前,您必须将属性 "internal" 添加到图表中:

weight = g.new_edge_property('float')
vfilt = g.new_vertex_property('bool')
...
old_sub = gt.GraphView(g, vfilt)
old_sub.ep.weight = weight   # old_sub.ep is a dictionary of internal properties
sub = gt.Graph(old_sub, directed=False, prune=True)
sub_weight = sub.ep.weight   # copy of weight