我使用networkx的代码似乎每次运行时只运行一次。我不确定为什么会这样。
import networkx as nx
import matplotlib.pyplot as plt
edgelist=[1,2,1,3,1,4,1,5,1,2,4,5,2,5,2,5,6,3]
e=edgelist
def global_clustering(list_of_edges):
return global_cluster(list_of_edges)
def makegraph(g):
graph1 = nx.Graph()
graph1.add_nodes_from(nodes(g))
g1=g
while len(g1)>0:
graph1.add_edge(g1[0], g1[1])
del g1[0:2]
return graph1
def global_cluster(list1):
graph=makegraph(list1)
print nx.transitivity(graph)
真的,我只是想找到图的传递性,否则称为全局聚类系数。它是networkx附带的功能。 谢谢你的帮助
答案 0 :(得分:0)
我觉得这样的事情就是你想要的:
import networkx as nx
edgelist=[1,2,1,3,1,4,1,5,1,2,4,5,2,5,2,5,6,3]
edges = zip(edgelist[::2],edgelist[1::2])
graph = nx.Graph(edges)
print(nx.transitivity(graph))