【问题标题】:subgraph from selected vertices using python-igraph使用 python-igraph 从选定的顶点生成子图
【发布时间】:2015-03-16 16:32:20
【问题描述】:

我正在尝试创建一个修剪过的子图,其中包含来自具有高中介中心性的图的顶点。

这是我的方法:

>>> import igraph as ig
>>> import numpy as np

>>> ig.summary(graph)
IGRAPH DNW- 9358 35488 -- 
+ attr: id (v), label (v), name (v), weight (e)

>>> btwn = graph.betweenness(weights='weight')
>>> ntile = np.percentile(btwn, 95)
>>> pruned_vs = graph.vs.select([v >= ntile for v in btwn])
>>> pruned_graph = graph.subgraph(pruned_vs)

一切运行良好。但是,生成的子图构造不正确。

>>> ig.summary(pruned_graph)
IGRAPH DNW- 0 0 -- 
+ attr: id (v), label (v), name (v), weight (e)

我尝试将implementation 属性更改为subgraph,但这并没有帮助。我错过了什么?

【问题讨论】:

    标签: python igraph


    【解决方案1】:

    此行不正确:

    pruned_vs = graph.vs.select([v >= ntile for v in btwn])
    

    您作为参数传递给select() 的列表推导返回一个布尔向量,graph.vs.select() 不支持该向量 - 您需要传递一个包含要选择的节点索引的向量。这可以按如下方式完成:

    pruned_vs = graph.vs.select([v for v, b in enumerate(btwn) if b >= ntile])
    

    【讨论】:

    • 谢谢,原来如此!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2013-01-21
    • 1970-01-01
    相关资源
    最近更新 更多