简体   繁体   中英

Multi edge python igraph questions

If you have a directed multi edge weighted graph, how do you do these things?

  1. For vertices I and J, list all edges from I to J.
  2. Delete all edges in the graph with weight more than 10.

For 1 I can list all the outgoing edges and then filter by destination node. This seems potentially inefficient, is there some way of just getting the edges directly? For 2 I can list all the edges, look up each weight and then delete the edge if needed. Is there a neat idiomatic way of doing this?

As for #1, unfortunately there is no easier solution than the one you mentioned (ie querying all the outgoing edges and then filtering based on the destination). The C core of igraph has a function called igraph_get_eids_multi which would do what you want, but there is no corresponding Python interface for the function.

As for #2, you can do this (assuming that g is your graph object, weight is the name of the edge attribute holding the weights, and gt stands for "greater than"):

g.es.select(weight_gt=10).delete()

where g.es represents the edge sequence of the whole graph, and its select method subsets the edge sequence based on some criteria (see the documentation of EdgeSeq.select for more details), returning another EdgeSeq . The delete() method of the filtered edge sequence then deletes the edges.

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