python_networkx包 计算带权有向图的皮尔森系数(同配系数)

现要计算一带权有向图的皮尔森系数,发现一函数:

degree_pearson_correlation_coefficient(G, x='out', y='in', weight=None, nodes=None)

其中weight参数的说明为:weight (string or None, optional (default=None)) – The edge attribute that holds the numerical value used as a weight. If None, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node

请问“”weight“”后面应该等于什么,才能调用weight参数?比如“weight=None”,则默认每条边的权重为1.

谢谢!!

>>> G=nx.path_graph(4)
>>> r=nx.degree_pearson_correlation_coefficient(G) 
>>> print("%3.1f"%r)
-0.5

你就运行他会自动计算weight

 

参考degree_pearson_correlation_coefficient — NetworkX 1.9 documentation 

如果前面获取到weight值,设置weight=weight即可按照设定的权重计算出皮尔森系数

...

weight 后面等于边的属性,可以是比如distance之类,自己定义的(就是可以给边加权重)

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632