简体   繁体   中英

selecting edges based on source/target in igraph

is there an easy way to select/delete edges based on their source and target in igraph?

what I am using is essentially

g.es["source"] = [e.source for e in g.es]
g.es["target"] = [e.target for e in g.es]    
g.es["tuple"]  = [e.tuple  for e in g.es]        

g.es.select(target=root)

but I feel like there should be a way to do that without storing source/target info twice.

Just use _source=whatever and _target=whatever as keyword arguments to select , eg:

g.es.select(_source=root)

Alternatively, you can use the incident method of the graph, which gives you a list of edge IDs instead of a filtered EdgeSeq if that is better for your purposes:

g.incident(root, mode="out")

BTW, for 'tuple', you want to use _between :

g.es.find(_between=((source_id,), (target_id,)))

It looks strange - if you use select instead of find , and pass in tuples with multiple indices, you'll actually get a list of edges instead of a single one. But for a single edge, have to still pass a tuple for start and end.

This is way faster for some reason (like, 3 orders of magnitude faster!) than using a combination of _source and _target , but gives the exact same information.

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