import matplotlib.pyplot as plt
import networkx as nx
G = nx.read_gml('data_sets/karate.gml' , label='id')
nx.degree(G).values()
通过使用上述代码,我想找到nx.degree(g(的字典的值。
但是终端正在抛出一个错误:'
degryView'对象没有属性'值'
在这里,语句nx.degree(g(的输出为:
DegreeView({1: 16, 2: 9, 3: 10, 4: 6, 5: 3, 6: 4, 7: 4, 8: 4, 9: 5, 10: 2, 11: 3, 12: 1, 13: 2, 14: 5, 15: 2, 16: 2, 17: 2, 18: 2, 19: 2, 20: 3, 21: 2, 22: 2, 23: 2, 24: 5, 25: 3, 26: 3, 27: 2, 28: 4, 29: 3, 30: 4, 31: 4, 32: 6, 33: 12, 34: 17})
正如您可以从输出中看到的那样,nx.degree
的返回值是DegreeView
对象。您可以使用dict()
将其转换为dictionary
。对于您的示例,将是:
G = nx.read_gml('data_sets/karate.gml' , label='id')
print(dict(nx.degree(G)).values())