Nov-24-2020, 11:54 PM
There's a Stackoverflow question on it, and other than a numpy solution (which is np.clip()), none of them appear to be as readable as your attempt to me.
I wasn't aware of it, but looks like a more common name for that function is
I wasn't aware of it, but looks like a more common name for that function is
clamp()
, and some libraries might have an implementation, but not any in the standard library.