返回属性名称Networkx Python [英] Return attribute name Networkx Python
本文介绍了返回属性名称Networkx Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此数据:
G.node['node']['a']['initial'] = 100
G.node['node']['a']['final'] = 10
G.node['node']['a']['initial'] = 500
G.node['node']['b']['final'] = 15
我需要进行以下计算:
min(G.node[node]['a']['final'],G.node[node]['b']['final']) / the initial attribute of the node that has the min final value.
= 10/100
我不知道该告诉谁python 10属于节点G.node ['node'] ['a'].谢谢!
I do not know who to tell python that 10 belongs to the node G.node['node']['a']. Thanks!
推荐答案
您可以使用min
函数的key
参数来执行此操作.
You can use the key
parameter of min
function to do this.
min_node = min(['a', 'b'], key=lambda x: G.node['node'][x]['final'])
result = G.node['node'][min_node]['final'] / G.node['node'][min_node]['initial']
这篇关于返回属性名称Networkx Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文