networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
modularity_matrix(G, nodelist=None, weight=None)

The modularity matrix is the matrix B = A - <A>, where A is the adjacency matrix and <A> is the average adjacency matrix, assuming that the graph is described by the configuration model.

More specifically, the element B_ij of B is defined as

$$A_{ij} - {k_i k_j \over 2 m}$$

where k_i is the degree of node i, and where m is the number of edges in the graph. When weight is set to a name of an attribute edge, Aij, k_i, k_j and m are computed using its value.

Parameters

G : Graph

A NetworkX graph

nodelist : list, optional

The rows and columns are ordered according to the nodes in nodelist. If nodelist is None, then the ordering is produced by G.nodes().

weight : string or None, optional (default=None)

The edge attribute that holds the numerical value used for the edge weight. If None then all edge weights are 1.

Returns

B : Numpy matrix

The modularity matrix of G.

Returns the modularity matrix of G.

See Also

adjacency_matrix
directed_modularity_matrix
modularity_spectrum
to_numpy_array

Examples

>>> k = [3, 2, 2, 1, 0]
... G = nx.havel_hakimi_graph(k)
... B = nx.modularity_matrix(G)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.linalg.modularitymatrix.modularity_matrix networkx.linalg.spectrum.modularity_spectrum networkx.linalg.modularitymatrix.directed_modularity_matrix

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/linalg/modularitymatrix.py#9
type: <class 'function'>
Commit: