【问题标题】:How to access the eigenvector centralities of all vertices in graph-tool?如何访问图形工具中所有顶点的特征向量中心性?
【发布时间】:2019-10-10 11:46:01
【问题描述】:

我需要访问图中所有顶点的特征向量中心值。我正在使用图形工具来做到这一点。

我试图像计算接近中心性一样计算它,但由于在图形工具中接近只返回顶点属性映射,而特征向量返回(加权)邻接矩阵的最大特征值和顶点属性映射,它的工作方式不同.

node_closeness = []
for vertex in G.vertices():
    a = closeness(G)[vertex]
    node_closeness.append(a)

此代码适用于接近性,但适用于特征向量:

node_eigenvector = []
for vertex in G.vertices():
    a = eigenvector(G)[vertex]
    node_eigenvector.append(a)

不工作。

所以,它给了我这个错误:

a = eigenvector(G)[vertex]

TypeError: tuple indices must be integers, not Vertex

但我认为这是因为特征向量同时返回特征值和顶点属性映射。有谁知道如何解决这个问题?

【问题讨论】:

    标签: python python-3.x graph eigenvector graph-tool


    【解决方案1】:

    特征向量中心性返回两个值是对的,因此为了访问 VertexPropertyMap,您需要先解包这些值:

    import graph_tool.all as gt
    g = gt.lattice([3,3], periodic=True)
    
    max_eigenvalue, eigenvector_property_map = gt.eigenvector(g)
    eigenvector_property_map[vertex]
    

    documentation 有一个更完整的例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      • 1970-01-01
      • 2021-09-20
      • 2010-12-12
      相关资源
      最近更新 更多