def downsample_image(image, n):
    """Downsample 2D input image n x n.

    Parameters
    ----------
    image : ndarray
        2D input image.
    n : int
        Downsampling factor, applied to both image dimensions.
    Returns
    -------
    result : ndarray
        Resampled image with shape = image.shape//n.
    """
    ny, nx = image.shape
    ny = (ny//n) * n
    nx = (nx//n) * n
    result = image[0:ny, 0:nx].reshape(ny//n,n,nx//n,n).mean(axis=-1).mean(axis=-2)
    return result