def get_index_of_csr_data(i, j, indptr, indices):
    """
    Get the value index of the i,j-element of a matrix in CSR format.

    Parameters
    ----------
    i : int
        row index which is asked to get the CSR-index for
    j : int
        column index which is asked to get the CSR-index for
    indptr : ndarray
        index-ptr-Array of the CSR-Matrix.
    indices : ndarray
        indices array of CSR-matrix (represents the nonzero column indices)

    Returns
    -------
    k : int
        index of the value array of the CSR-matrix, in which value [i,j] is stored.

    Notes
    -----
    This routine works only, if the tuple i,j is acutally a real entry of the matrix. Otherwise the value k=0 will be
    returned and an Error Message will be provided.
    """

    # indices for row i are stored in indices[indptr[k]:indptr[k+1]]; thus the indptr marks the start and end of the
    # part of the indices and val vector where all entries of a row are stored

    # set k to the start of data of row k
    k = indptr[i]
    # search for appearance of j in the nonzero column indices which are stored in indices[k] till
    # indices[k+indptr[i+1]]
    while j != indices[k]:
        # while column j not found search for j in next entry
        k += 1
        # Check if next search would be in next (wrong) row
        if k > indptr[i + 1]:
            print('ERROR! The index in the csr matrix is not preallocated!')
            k = 0
            break
    return k