def _make_laplacian_sparse(edges, weights):
 pixel_nb = (edges.max() + 1)
 diag = np.arange(pixel_nb)
 i_indices = np.hstack((edges[0], edges[1]))
 j_indices = np.hstack((edges[1], edges[0]))
 data = np.hstack(((- weights), (- weights)))
 lap = sparse.coo_matrix((data, (i_indices, j_indices)), shape=(pixel_nb, pixel_nb))
 connect = (- np.ravel(lap.sum(axis=1)))
 lap = sparse.coo_matrix((np.hstack((data, connect)), (np.hstack((i_indices, diag)), np.hstack((j_indices, diag)))), shape=(pixel_nb, pixel_nb))
 return lap.tocsr()

def _make_laplacian_sparse ( edges , weights ) : pixel_nb = ( edges . max ( ) + 1 ) diag = np . arange ( pixel_nb ) i_indices = np . hstack ( ( edges [ 0 ] , edges [ 1 ] ) ) j_indices = np . hstack ( ( edges [ 1 ] , edges [ 0 ] ) ) data = np . hstack ( ( ( - weights ) , ( - weights ) ) ) lap = sparse . coo_matrix ( ( data , ( i_indices , j_indices ) ) , shape = ( pixel_nb , pixel_nb ) ) connect = ( - np . ravel ( lap . sum ( axis = 1 ) ) ) lap = sparse . coo_matrix ( ( np . hstack ( ( data , connect ) ) , ( np . hstack ( ( i_indices , diag ) ) , np . hstack ( ( j_indices , diag ) ) ) ) , shape = ( pixel_nb , pixel_nb ) ) return lap . tocsr ( )
sparse implementation .