simplify code by using np.clip