繁体   English   中英

Graph-Tool GraphView对象

[英]Graph-Tool GraphView Object

我有一个使用graph-tool的GraphView()生成的过滤图。

g = gt.GraphView(g, vfilt= label_largest_component(g, directed=False))

原始图g具有10,069个顶点,而所得图具有9,197个顶点。 但是,使用新的(过滤后的)图,当我使用indeg = g.degree_property_map("in")列出in-degrees时, list(indeg.a)的元素总数仍为10,069。 当绘制具有9,197个节点的新的经过过滤的图时,这变得有问题,其中顶点大小被设置为indeg的函数, indeg主要是因为元素数量不匹配。

代码段如下所示

g = load_graph("ppnet.xml")
g = GraphView(g, vfilt=label_largest_component(g, directed=False))
indeg = g.degree_property_map("in")
indeg.a = np.sqrt(indeg.a) + 2
graph_draw(g, vertex_size = indeg, vertex_fill_color=indeg, pos = sfdp_layout(g),
    vcmap=plt.cm.gist_heat, output_size=(400, 400), output="gc.png")

运行时会给出以下ValueError

ValueError: operands could not be broadcast together with shapes (10069,) (9197,) 

GraphView对象添加预期样式的正确方法是什么?

找到了解决方案。 我首先创建了GraphView对象的副本 ,然后清除了此副本的顶点。 注意,为了保持清晰,我引入了一个新的变量gc ,而不是保留变量名g

g = load_graph("ppnet.xml")
gc = GraphView(g, vfilt=label_largest_component(g, directed=False)).copy()
gc.purge_vertices()
indeg = gc.degree_property_map("in")
indeg.a = np.sqrt(indeg.a)+2
graph_draw(gc, vertex_size = indeg, vertex_fill_color=indeg, pos = sfdp_layout(gc),
    vcmap=plt.cm.gist_heat, output_size=(400, 400), output="gc.png")

暂无
暂无

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

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