def DW_matrices(graph):
 W = nx.to_scipy_sparse_matrix(graph, format='csc')
 entries = W.sum(axis=0)
 D = sparse.dia_matrix((entries, 0), shape=W.shape).tocsc()
 return (D, W)

def DW_matrices ( graph ) : W = nx . to_scipy_sparse_matrix ( graph , format = 'csc' ) entries = W . sum ( axis = 0 ) D = sparse . dia_matrix ( ( entries , 0 ) , shape = W . shape ) . tocsc ( ) return ( D , W )
returns the diagonal and weight matrices of a graph .