igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] average path length for graphs containing multiple componen


From: Tamás Nepusz
Subject: Re: [igraph] average path length for graphs containing multiple components
Date: Wed, 21 Nov 2012 14:11:12 +0100

Hi,

> how is the average path length calculated for graphs that contain more than 
> one component? 
Depending on the value of the "unconn" parameter of the function, there are two 
possible behaviours:

- If "unconn" is False, igraph simply assumes for every disconnected vertex 
pair that their distance is N, where N is the number of vertices in the graph.

- If "unconn" is True, igraph calculates distances for the connected pairs only 
and then takes the average of these values. In your graph, it goes as follows:

path_lengths = [pl for pl in sum(g.shortest_paths(), []) if pl > 0 and pl != 
float('inf')]

Now, sum(path_lengths) is 68 and len(path_lengths) is 34, so you get a result 
of 2.0.

-- 
T.




reply via email to

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