def subsample_fourier(x, k):
    """Subsampling in the Fourier domain.

    Subsampling in the temporal domain amounts to periodization in the Fourier
    domain, so the input is periodized according to the subsampling factor.

    Parameters
    ----------
    x : numpy array
        Input numpy array with at least 3 dimensions.
    k : int
        The subsampling factor.

    Returns
    -------
    res : numpy array
        The input numpy array periodized along the last axis to yield a
        numpy array of size x.shape[-2] // k along that dimension.
        
    """
    N = x.shape[-1]
    res = x.reshape(x.shape[:-2] + (k, N // k)).mean(axis=-2, keepdims=True)
    return res