def prepare(x, downscale=3):
    """Normalize images to [-1, 1] and downscale them to 100x100x3 (for faster training) and flatten them."""
    s = x.shape
    x = x.astype('f').reshape((s[0], s[1] // downscale, downscale, s[2] // downscale, downscale, s[3]))
    return x.mean((2, 4)).reshape((s[0], -1)) * (1 / 127.5) - 1