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
, 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")
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With