我想在python中计算网络图的所有边缘权重之和。实际上,我有88000多个边,因此需要3个小时以上才能完成。有什么解决方案可以减少执行时间? 这是计算每个给定边缘的权重的函数:
def weight_edge(i,j,g):
neighborhood_i=neighborhood(g,i)
neighborhood_j=neighborhood(g,j)
neighborhood_commun=len(intersection(neighborhood_i,neighborhood_j))
neighborhood_total=len(neighborhood_i)+len(neighborhood_j)
if(neighborhood_total-2!=0):
return(round(neighborhood_commun/(neighborhood_total-2),3))
else:
return 0
其中i和j是两个相连的节点,而g是图。