我使用以下命令从csv文件创建网络:
adj_mat = np.loadtxt("outputsnet/output.csv",delimiter=',',skiprows=0)
net = nx.from_numpy_matrix(adj_mat, create_using=nx.DiGraph())
当我这样做时:
w=net.edges(data=True)
print w
我得到了这个结果:
[(51, 92, {'weight': 589.0}), (51, 95, {'weight': 579.0}), (53, 82, {'weight': 644.0}), (56, 83, {'weight': 644.0}), (58, 93, {'weight': 589.0}), (59, 84, {'weight': 644.0}), (62, 96, {'weight': 579.0}), (64, 97, {'weight': 579.0}), (65, 89, {'weight': 599.0}), (65, 98, {'weight': 579.0}), (66, 99, {'weight': 579.0})]
但是当我尝试通过这样做来计算特征向量中心性时:
centrality = nx.eigenvector_centrality(net,weight='weight')
print(['%s %0.2f'%(node,centrality[node]) for node in centrality])
我发现所有权重都等于0,因为我没有定义权重参数:
['64 0.00', '65 0.00', '66 0.00', '99 0.00', '51 0.00', '97 0.00', '96 0.00', '98 0.00', '82 0.00', '83 0.00', '84 0.00', '53 0.00', '56 0.00', '89 0.00', '58 0.00', '59 0.00', '92 0.00', '93 0.00', '62 0.00', '95 0.00']
您可以帮助我定义在我的示例中用作权重的边缘属性吗?