Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selecting edges based on source/target in igraph

Tags:

python

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.

like image 799
bpeter Avatar asked Jan 29 '13 23:01

bpeter


2 Answers

Just use _source=whatever and _target=whatever as keyword arguments to select, e.g.:

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")
like image 51
Tamás Avatar answered Nov 15 '22 14:11

Tamás


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.

like image 23
Corley Brigman Avatar answered Nov 15 '22 15:11

Corley Brigman