在大型NetworkX图中删除tie = 1的节点 [英] Deleting nodes with tie=1 in a large NetworkX graph

查看:72
本文介绍了在大型NetworkX图中删除tie = 1的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用NetworkX制作了大约20,000个节点的大型图形.我想删除只有一个领带(或零领带)的节点,以减少混乱.由于它是一个非常大的图,因此我不知道按领带或1或0的名称或ID的节点.

I have made large graph with NetworkX with about 20,000 nodes. I would like to delete nodes with only one tie (or zero ties) to try to reduce the clutter. Since it is a very large graph I do not know the nodes by name or ID that have tie=1 or 0.

有人知道如何在不指定节点ID或名称的情况下删除这些节点吗?

Does anyone know how to delete these nodes without specifying the node ID or name?

推荐答案

Graph g 上迭代会产生 g 的所有节点,一次一次-我相信您不能在迭代过程中更改 g ,但是您可以有选择地列出要删除的节点列表,然后将其全部删除:

Iterating on a Graph g yields all of g's nodes, one at a time -- I believe you can't alter g during the iteration itself, but you can selectively make a list of nodes to be deleted, then remove them all:

to_del = [n for n in g if g.degree(n) <= 1]
g.remove_nodes_from(to_del)

这篇关于在大型NetworkX图中删除tie = 1的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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