代码之家  ›  专栏  ›  技术社区  ›  8-Bit Borges

Networkx-最大弱连接组件中节点的分数

  •  2
  • 8-Bit Borges  · 技术社区  · 4 年前

        # from dataframe
        matrix_weak = matrix.copy()
        # to numpy arrays
        matrix_weak_to_numpy = matrix_weak.to_numpy()
        G = nx.from_numpy_matrix(matrix_weak_to_numpy)
        G = G.to_directed() # weakly connected component needs a directed 
    

    图表

        max_wcc = max(nx.weakly_connected_components(G), key=len)
        max_wcc = nx.subgraph(G, max_wcc)
    

    1 回复  |  直到 4 年前
        1
  •  0
  •   SultanOrazbayev    4 年前

    网络中的节点总数为 G.number_of_nodes()

    fraction = max_wcc.number_of_nodes() / G.number_of_nodes()