r"""Error-perturbation arising from a given sensitivity

    Parameters
    ----------
    C : (M, M) ndarray
        Count matrix
    S : (K, M, M) ndarray
        Sensitivity tensor

    Returns
    -------
    X : (K, K) ndarray
        Covariance matrix for given sensitivity

def error_perturbation_cov(C, S):
    r"""Error-perturbation arising from a given sensitivity

    Parameters
    ----------
    C : (M, M) ndarray
        Count matrix
    S : (K, M, M) ndarray
        Sensitivity tensor

    Returns
    -------
    X : (K, K) ndarray
        Covariance matrix for given sensitivity

    """
    K = S.shape[0]
    X = np.zeros((K, K))
    cov = tmatrix_cov(C)
    for i in range(K):
        for j in range(K):
            Q = S[i, :, :]
            R = S[j, :, :]
            X[i, j] = (Q[:, :, np.newaxis] * cov * R[:, np.newaxis, :]).sum()
    return X