diag_elems = A.data[idx_begin:idx_end]
diag_indices = A.indices[idx_begin:idx_end]
ith_diag = sparse.csc_matrix((diag_elems, (diag_indices, diag_indices)),
    shape=(A.shape[1], A.shape[1]))
ith_diag.eliminate_zeros()
Create a sparse diagonal matrix from row of a sparse matrix