def clip(a, a_min, a_max):
    if not isinstance(a, np.ndarray):
        max_mask = (a > a_max)
        max_tar = gp.ones(a.shape) * a_max
        min_mask = (a < a_min)
        min_tar = gp.ones(a.shape) * a_min
        a_clipped = (
            a * (1 - max_mask - min_mask)
            + max_tar * max_mask + min_tar * min_mask)
        return a_clipped
    else:
        return np.clip(a, a_min, a_max)
Clip (limit) the values in an array.
dataset/ETHPy150Open BRML/climin/climin/mathadapt.py/clip