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
data_helpers.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录