Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Maybe faster than that:

def ChangeVertices(g,di):  
    G=Graph()
    for v in di.values():
        G.add_vertex(v)
    for e in g.edge_iterator():
        G.add_edge(di[e[0]] if e[0] in di else e[0],di[e[1]] if e[1] in di else e[1])
    return(G)

def GraphFromZero(g):
    return(ChangeVertices(g,{v:i for i,v in enumerate(g.vertices())}))