【发布时间】:2022-01-15 20:20:22
【问题描述】:
我的网络有几个连接的组件。 我需要为它们中的每一个计算直径和半径。
我试图循环遍历它们中的每一个,但是出了点问题(错误:AttributeError: 'set' object has no attribute 'order')
N_comp=[len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)] # this should return the maximum number of connected components in the network
for i in range(N_comp):
# Calculate average diameter and average path length of connected components
print('Average diameter:{}'.format(nx.diameter(nx.connected_components(G), key=len))))
print('average path length: {}'.format(nx.average_shortest_path_length(nx.connected_components(G), key=len)))
【问题讨论】: