def match_lightness(img, ref_img):
    if ref_img.ndim == 3:
        ref_grayscale = ref_img.mean(-1)
    else:
        ref_grayscale = ref_img

    new_img = img.mean(-1, keepdims=True) + ref_grayscale[..., np.newaxis] - img
    return new_img.clip(0, 1)
dataset/ETHPy150Open gustavla/autocolorize/autocolorize/color.py/match_lightness/swapped operands of `-`