I am trying to run this code:
JavaScript
x
4
1
graph = nx.Graph()
2
3
largest_subgraph = max(nx.connected_component_subgraphs(graph), key=len)
4
But I am getting this error message:
JavaScript
1
2
1
AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'
2
How do I get around that?
Advertisement
Answer
connected_component_subgraphs() has been removed from version 2.4.
Instead, use this:
JavaScript
1
6
1
graph = nx.Graph()
2
3
connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))
4
5
largest_subgraph = max(connected_component_subgraphs, key=len)
6
according to this answer.