简体   繁体   English

如何删除igraph python中没有边的所有顶点?

[英]How to delete all vertices that have no edges in igraph python?

I have a graph with a lot of vertices without edges. 我有一个带有很多没有边的顶点的图。

IGRAPH UN-- 560 49 -- 
+ attr: area (v), cnpj (v), grande_area (v), name (v), res (v), std (v), company (e), res (e), std (e)

I would like to delete all vertices that have no edges... Something like: 我想删除所有没有边的顶点...

 to_delete_ids = [v.index for v in g_groups_all.vs if v HAS NO EDGES]
 g_groups_all.delete_vertices(to_delete_ids)

But I don't know how to write the conditional to check if the vertex has no edges. 但是我不知道如何编写条件来检查顶点是否没有边。 I tried v._source == None or v._target != True with no success. 我尝试了v._source == None or v._target != True ,没有成功。

My edges e['company'] e['res'] and e['std'] can be True or None 我的边e['company'] e['res'] and e['std']可以为TrueNone

Embarrassed to have asked such a question. 不好意思问了这样一个问题。 Of course... 当然...

 to_delete_ids = [v.index for v in g_groups_all.vs if v.degree() == 0]
 g_groups_all.delete_vertices(to_delete_ids)

Obviously! 明显! But it took me some time to come up with that... 但是我花了一些时间才想出...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM