Pratik Parija
Pratik Parija

Reputation: 27

Error for max(nx.connected_component_subgraphs(),) no attribute 'connected_component_subgraphs'

I am trying to run this code:

graph = nx.Graph()

largest_subgraph = max(nx.connected_component_subgraphs(graph), key=len)

But I am getting this error message:

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'

How do I get around that?

Upvotes: 2

Views: 1370

Answers (1)

Jesper
Jesper

Reputation: 1649

connected_component_subgraphs() has been removed from version 2.4.

Instead, use this:

graph = nx.Graph()

connected_component_subgraphs = (graph.subgraph(c) for c in nx.connected_components(graph))

largest_subgraph = max(connected_component_subgraphs, key=len)

according to this answer.

Upvotes: 7

Related Questions