简体   繁体   中英

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.

My edges e['company'] e['res'] and e['std'] can be True or None

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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