简体   繁体   中英

Deleting an edge between two vertices [igraph python]

I can't believe I'm having a hard time with this, but here we are... This should be straight forward, here's my code:

i = random.choice(ER.vs)
j = random.choice(ER.vs)

if t < 1:
    ER.add_edge(i,j)
else:
    ER.delete_edges(ER.get_eid(i.index,j.index))

The last line doesn't work. I've tried different ways to delete the edge between i and j, but I can't seem to figure out the function. Could anyone help?

Cheers!

For me it works with igraph0.6:

import random
import igraph

N = 10
g = igraph.Graph.Full(N)
i, j = random.sample(range(g.vcount()), 2)
g.delete_edges([(i,j)])
print(g.ecount(), N*(N-1)/2)

From the output can be concluded, it has deleted one edge:

44 45.0

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