NetworkX largest component no longer working?

前端 未结 2 363
Happy的楠姐
Happy的楠姐 2021-01-04 06:14

according to networkx documentation, connected_component_subgraphs(G) returns a sorted list of all components. Thus the very first one should be the largest component.

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-04 06:22

    The networkx-1.9 documentation is here http://networkx.github.io/documentation/networkx-1.9/reference/generated/networkx.algorithms.components.connected.connected_components.html#networkx.algorithms.components.connected.connected_components

    The interface was changed to return a generator (as you figured out). The example in the documentation shows how to do what you ask.

    Generate a sorted list of connected components, largest first.

    >> G = nx.path_graph(4)
    >>> G.add_path([10, 11, 12])
    >>> sorted(nx.connected_components(G), key = len, reverse=True)
    [[0, 1, 2, 3], [10, 11, 12]]
    

    or

    >>> sorted(nx.connected_component_subgraphs(G), key = len, reverse=True)
    

提交回复
热议问题