@not_implemented_for('directed')
@not_implemented_for('multigraph')
def modularity_matrix(G, nodelist=None, weight=None):
 if (nodelist is None):
  nodelist = list(G)
 A = nx.to_scipy_sparse_matrix(G, nodelist=nodelist, weight=weight, format='csr')
 k = A.sum(axis=1)
 m = (k.sum() * 0.5)
 X = ((k * k.transpose()) / (2 * m))
 return (A - X)

@ not_implemented_for ( 'directed' ) @ not_implemented_for ( 'multigraph' ) def modularity_matrix ( G , nodelist = None , weight = None ) : if ( nodelist is None ) : nodelist = list ( G ) A = nx . to_scipy_sparse_matrix ( G , nodelist = nodelist , weight = weight , format = 'csr' ) k = A . sum ( axis = 1 ) m = ( k . sum ( ) * 0.5 ) X = ( ( k * k . transpose ( ) ) / ( 2 * m ) ) return ( A - X )
return the modularity matrix of g .