niz
niz

Reputation: 73

Python igraph density function for directed graphs

Does python igraph function 'G.density()' calculate the density for an undirected graph only? I want to calculate the density for an directed graph. Must I divide by 2? There is an option for 'loop'=True or False but there is no option for directed or undirected graph. I know that for an undirected graph, the density is

2m/n(n-1)

while for directed graph it us

m/n(n-1)

I am not seeing anything in the documentation.

Upvotes: 1

Views: 737

Answers (1)

Sos
Sos

Reputation: 1949

Yes, it is there:

 g.density(loops=False)

The important part comes in defining your graph object g as directed or undirected. The density() method will take that into account for your computation

Upvotes: 1

Related Questions