data_helpers.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:TextAsGraphClassification 作者: NightmareNyx 项目源码 文件源码
def neighbors2_community(G, remove_duplicates=True, use_kcore=False):
    Gc = None
    if use_kcore:
        Gc = G.copy()
        Gc.remove_edges_from(Gc.selfloop_edges())
        Gc = nx.k_core(Gc, 3)
        # Gc = [cl for cl in nx.find_cliques(G)]
    else:
        Gc = G

    communities = set()

    for v in Gc.nodes():
        neighs = G.neighbors(v)
        community = []
        for n in neighs:
            community.append(n)
            neighs2 = G.neighbors(n)
            community.extend(neighs2)
        if remove_duplicates:
            community = list(set(community))
        communities.add(tuple(community))

    communities = list(map(list, communities))  # Convert tuples back into lists
    return communities
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号