如何在图形工具中访问所有顶点的特征向量中心点?

问题描述 投票:0回答:1

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

我试图像紧密度中心度那样计算它,但是由于在图形工具中紧密度仅返回顶点属性图,而特征向量既返回(加权)邻接矩阵的最大特征值又返回顶点属性图,因此它的工作方式不同。

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个回答
0
投票

您是正确的,本征向量中心性返回两个值,因此,要访问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有完整的示例。

© www.soinside.com 2019 - 2024. All rights reserved.