Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Networkx-索引器:使用(贪婪的模块化)社区时列表索引超出范围_Python 3.x_Networkx_Modularity - Fatal编程技术网

Python 3.x Networkx-索引器:使用(贪婪的模块化)社区时列表索引超出范围

Python 3.x Networkx-索引器:使用(贪婪的模块化)社区时列表索引超出范围,python-3.x,networkx,modularity,Python 3.x,Networkx,Modularity,我正在使用Python 3.7.1和networkx 2.2。 我使用networkx生成我的有向图,我想用 在以下步骤中: import networkx as nx from networkx.algorithms.community import greedy_modularity_communities G=nx.DiGraph() G.add_nodes_from([1,10]) G.add_edges_from([(1,2),(3,4),(5,6),(7,1),(2,10),(3,8

我正在使用Python 3.7.1和networkx 2.2。 我使用networkx生成我的有向图,我想用 在以下步骤中:

import networkx as nx
from networkx.algorithms.community import greedy_modularity_communities
G=nx.DiGraph()
G.add_nodes_from([1,10])
G.add_edges_from([(1,2),(3,4),(5,6),(7,1),(2,10),(3,8),(9,8)])
c = list(greedy_modularity_communities(G))
sorted(c[0])
我收到一个错误:

索引器:列表索引超出范围


我怀疑你的问题在于你的图是有方向的。
贪婪的模块化社区
的文档表明它期望输入是一个
,但你的是一个
有向图

如果我这样做

H = nx.Graph(G)
c = list(greedy_modularity_communities(H))

我没有收到错误。我不确定它在
H
中找到的社区是否是您感兴趣的社区。

您能提供完整的错误消息吗?当然,我在问题中添加了代码示例,完整的错误消息与我在索引器之前编写的一样。完整的错误消息将包含更多信息,而不仅仅是索引错误(例如,它将说明哪个包的哪一行产生了错误)。