def distance_mean_elements(K, T1, T2):
    """ Compute the squared distance between mean elements of two time series

    Parameters
    ----------
    K: (T1+T2) x (T1+T2) array,
        between frames kernel matrix

    T1: int,
        duration of time series 1

    T2: int,
        duration of time series 2

    Returns
    -------
    dme2: double,
          squared distance between the mean-elements in RKHS
    """
    dme2 = K[:T1, :T1].mean()
    dme2 += K[T1:, T1:].mean()
    dme2 += -2.0 * K[:T1, T1:].mean()
    # # normalization vector
    # m = np.zeros((T1+T2, 1), dtype=np.double)
    # m[:T1,:] = -1./T1
    # m[T1:,:] = 1./T2
    # # return the distance
    # dme2 = np.dot(m.T, np.dot(K, m))[0,0]
    return dme2