def compute_Rk(L,A,n_samples):<EOL>
laplacian_matrix = L.copy()<EOL>laplacian_matrix.setdiag(<NUM_LIT:0>)<EOL>laplacian_matrix.eliminate_zeros()<EOL>n = n_samples<EOL>Rk_tensor = []<EOL>nbk = []<EOL>row_A,column_A = A.T.nonzero()<EOL>row,column = laplacian_matrix.nonzero()<EOL>nnz_val = np.squeeze(np.asarray(laplacian_matrix.T[(row,column)]))<EOL>sorted_col_args = np.argsort(column)<EOL>sorted_col_vals = column[sorted_col_args]<EOL>breaks_row_A = np.diff(row_A).nonzero()[<NUM_LIT:0>]<EOL>breaks_col = np.diff(sorted_col_vals).nonzero()[<NUM_LIT:0>]<EOL>for k in range(n_samples):<EOL><INDENT>if k == <NUM_LIT:0>:<EOL><INDENT>nbk.append( column_A[:breaks_row_A[k]+<NUM_LIT:1>].T )<EOL>Rk_tensor.append(<EOL>nnz_val[np.sort(sorted_col_args[:breaks_col[k]+<NUM_LIT:1>])])<EOL><DEDENT>elif k == n_samples-<NUM_LIT:1>:<EOL><INDENT>nbk.append( column_A[breaks_row_A[k-<NUM_LIT:1>]+<NUM_LIT:1>:].T )<EOL>Rk_tensor.append(<EOL>nnz_val[np.sort(sorted_col_args[breaks_col[k-<NUM_LIT:1>]+<NUM_LIT:1>:])])<EOL><DEDENT>else:<EOL><INDENT>nbk.append( column_A[breaks_row_A[k-<NUM_LIT:1>]+<NUM_LIT:1>:breaks_row_A[k]+<NUM_LIT:1>].T )<EOL>Rk_tensor.append(nnz_val[np.sort(<EOL>sorted_col_args[breaks_col[k-<NUM_LIT:1>]+<NUM_LIT:1>:breaks_col[k]+<NUM_LIT:1>])])<EOL><DEDENT><DEDENT>return Rk_tensor, nbk<EOL>
Compute sparse L matrix and neighbors.

Returns
-------
Rk_tensor : array-like. Length = n
    each component correspond to the sparse matrix of Lk, which is
    generated by extracting the kth row of laplacian and removing zeros.
nbk : array-like. Length = n
    each component correspond to the neighbor index of point k, which is
    used in slicing the gradient, Y or S arrays.