使用Python在igraph中的巨型组件中节点的标识 [英] Identity of nodes in the giant component, in igraph with Python

查看:49
本文介绍了使用Python在igraph中的巨型组件中节点的标识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试标记哪些节点在网络的巨型组件中,哪些不在.我并不是想简单地抓住这个巨大的组成部分.这是我到目前为止的内容:

I'm trying to label which nodes are in the giant component of a network, and which are not. I am NOT trying to simply grab the giant component. This is what I have so far:

def in_giant(G):
    giant = G.components().giant().vs["name"]
    return map(lambda x: x in giant, G.vs["name"])

这很慢.我怀疑可以通过直接在 G.components()结构上进行操作来快速完成操作.有什么想法吗?

This is slow. I suspect there's something fast that can be done by operating on the G.components() structure directly. Any ideas?

推荐答案

我不确定我是否正确理解了您的问题,但似乎您只需要一个二进制列表(即包含 True 的列表)code>和 False 仅),以使列表中索引为 i 的项为true,前提是相应的顶点位于Giant组件中.您的解决方案很好,但是由于它取决于NumPy,所以我想添加一个不依赖于此的替代方法:

I'm not sure if I understand your question correctly, but it seems like you simply need a binary list (i.e. a list containing True and False only) such that the item at index i in the list is true iff the corresponding vertex is in the giant component. Your solution is fine, but since it depends on NumPy, I thought I'd add an alternative that does not depend on it:

def in_giant(G):
    cl = G.components()
    cl_sizes = cl.sizes()
    giant_component_index = cl_sizes.index(max(cl_sizes))
    return [x == giant_component_index for x in cl.membership]

这篇关于使用Python在igraph中的巨型组件中节点的标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆