[Top][All Lists]

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

Re: [igraph] average shortest path between same sets of nodes

From: Tamas Nepusz
Subject: Re: [igraph] average shortest path between same sets of nodes
Date: Thu, 20 Jan 2011 17:40:09 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7


To implement mean(), you have two choices:

1. Implement it yourself:

def mean(xs):
    return sum(xs) / float(len(xs))

2. Implement it using igraph's RunningMean class (this one works with
iterables as well, not just with sequences):

def mean(iterable):
    rm = RunningMean()
    rm << iterable
    return rm.mean

After that, you can simply do something like this:

vs = [idx for idx, type in enumerate(g.vs["type"]) if type is False]
mean(lcc.shortest_paths(source=vs, target=vs, mode="all")

igraph 0.6 also supports the following, I can't remember whether 0.5.4
also understands this or not, but it's worth a try:

target=g.vs(type=False), mode="all")


On 01/20/2011 05:04 PM, Simone Gabbriellini wrote:
> Hello again,
> After retrieving the largest connected component (lcc) of a bipartite
> graph, I would like to find the average shortest paths for top and
> bottom nodes. Is there something like this in the python interface:
> mean(shortest.paths(lcc, v=V(lcc)[type==FALSE],
> to=V(lcc)[type==FALSE], mode = 'all'))
> mean(shortest.paths(lcc, v=V(lcc)[type==TRUE], to=V(lcc)[type==TRUE],
> mode = 'all'))
> best,
> simone
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help

reply via email to

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