Use np.clip() instead of conditional so that function works on vectors