# Modularity (Q) based on the Louvain split, unexpected values

**URL:** <https://igraph.discourse.group/t/modularity-q-based-on-the-louvain-split-unexpected-values/159>\
**Category:** Usage\
**Tags:** Python\
**Created:** [29 March 2020 13:22 UTC](https://igraph.discourse.group/t/modularity-q-based-on-the-louvain-split-unexpected-values/159 "2020-03-29T13:22:06Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![makaros](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@makaros](https://igraph.discourse.group/u/makaros)\
**Post date:** [29 March 2020 14:04 UTC](https://igraph.discourse.group/t/modularity-q-based-on-the-louvain-split-unexpected-values/159/4 "2020-03-29T14:04:43Z")

</div>

Indeed that is the case. I expected igraph to understand this since I defined a weighted adjacency matrix but I need to **explicitly** pass the `weights` argument in `modularity()`.

```auto
import numpy as np
import scipy.io
from igraph import *
import bct

A = scipy.io.loadmat("A.mat")['A']
np.fill_diagonal(A,0.0)

# igraph
graph = Graph.Weighted_Adjacency(A.tolist(), mode=ADJ_UNDIRECTED, attr="weight", loops=False)
Louvain = graph.community_multilevel(weights=graph.es['weight'], return_levels=False)
Q = graph.modularity(Louvain, weights=graph.es['weight'])
print(Q)

#bctpy
com, q = bct.community_louvain(A)
print(q)

```

0.14133150351832535

0.14133150351832674

---

_[View the full topic](https://igraph.discourse.group/t/modularity-q-based-on-the-louvain-split-unexpected-values/159)._
