PythonNetworkX:按边缘出现频率将权重添加到边缘

PythonNetworkX:按边缘出现频率将权重添加到边缘,第1张

Python / NetworkX:按边缘出现频率将权重添加到边缘

试试看它的大小。

注意:我添加了一个现有边的副本,目的只是为了显示当多图中有重复时的行为。

from collections import Counterc = Counter(g.edges())  # Contains frequencies of each directed edge.for u, v, d in g.edges(data=True):    d['weight'] = c[u, v]print(list(g.edges(data=True)))#[(340, 269, {'weight': 1}),# (340, 340, {'weight': 1}),# (269, 340, {'weight': 1}),# (398, 279, {'weight': 1}),# (69, 28, {'weight': 1}),# (382, 27, {'weight': 1}),# (27, 285, {'weight': 2}),# (27, 285, {'weight': 2}),# (120, 422, {'weight': 1}),# (422, 217, {'weight': 1}),# (217, 340, {'weight': 1}),# (458, 442, {'weight': 1}),# (291, 431, {'weight': 1}),# (68, 27, {'weight': 1}),# (112, 269, {'weight': 1})]

编辑: 要以边缘权重为厚度可视化图形,请使用以下命令:

nx.draw_networkx(g, width=[d['weight'] for _, _, d in g.edges(data=True)])


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5664526.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存