def eta(ranking, pref):
    """Return the (normalised) eta measure.

    Parameters
    ----------
    ranking : list or array-like
        ranking that stores id. Each id corresponds to the index of the comparison matrix.
    pref : list or array-like
        comparison matrix. Ensure that it satisfies pref[x][y] == 1 - pref[y][x] and 0 <= pref[x][y] <= 1. 

    Returns
    -------
    eta_mesure : float
        the value of eta measure for the ranking under the preference

    >>> eta([0, 1, 2], [[1, 1, 1], [0, 1, 1], [0, 0, 1]])
    1.0
    >>> eta([2, 1, 0], [[1, 1, 1], [0, 1, 1], [0, 0, 1]])
    -1.0
    >>> eta([2, 1, 3, 0], [[0.5, 0.2, 0.4, 0.3], [0.8, 0.5, 0.1, 0.4], [0.6, 0.9, 0.5, 0.4], [0.7, 0.6, 0.6, 0.5]])
    0.6666666666666667
    """

    N = len(ranking)
    ideal = 0
    _eta = 0
    for i in range(N):
        for j in range(i+1, N):
            x = ranking[i]
            y = ranking[j]
            p_ij = pref[x][y]
            delta_ij = 1 if i < j else -1
            true_delta_ij = 1 if p_ij > 0.5 else -1
            label = (2 * p_ij - 1)
            _eta += label * delta_ij
            ideal += label * true_delta_ij
    eta_measure = _eta / ideal
    return eta_measure