@not_implemented_for('directed')
def laplacian_matrix(G, nodelist=None, weight='weight'):
 import scipy.sparse
 if (nodelist is None):
  nodelist = list(G)
 A = nx.to_scipy_sparse_matrix(G, nodelist=nodelist, weight=weight, format='csr')
 (n, m) = A.shape
 diags = A.sum(axis=1)
 D = scipy.sparse.spdiags(diags.flatten(), [0], m, n, format='csr')
 return (D - A)

@ not_implemented_for ( 'directed' ) def laplacian_matrix ( G , nodelist = None , weight = 'weight' ) : import scipy . sparse if ( nodelist is None ) : nodelist = list ( G ) A = nx . to_scipy_sparse_matrix ( G , nodelist = nodelist , weight = weight , format = 'csr' ) ( n , m ) = A . shape diags = A . sum ( axis = 1 ) D = scipy . sparse . spdiags ( diags . flatten ( ) , [ 0 ] , m , n , format = 'csr' ) return ( D - A )
return the laplacian matrix of g .