igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] how to translate from R to Python...


From: Tamas Nepusz
Subject: Re: [igraph] how to translate from R to Python...
Date: Mon, 22 Sep 2008 15:05:08 +0100

I am a newbie to Python... can you give me an hint on how to translate this R code:

g2 <- subgraph(g, V(g) [ adj(E(g) [ color=="green" ]) ])
It's a little bit complicated since adj() is an R-specific extension to igraph. It takes an edge sequence and returns a boolean vector that is true for vertices that are adjacent to at least one of the edges. Something similar in Python can be implemented as a separate method:


def adj(es):
    result = set()
    for e in es: result.add(*e.tuple)
    return list(result)

g2 = g.subgraph(adj(g.es.select(color="green")))

--
Tamas





reply via email to

[Prev in Thread] Current Thread [Next in Thread]