Clip Values
EasyMachine LearningArray
Description
Given an array and a lower and upper bound, clip every value into the [lower, upper] range: values below the lower bound become the lower bound and values above the upper bound become the upper bound.
Examples
Input:
[1,5,-3,8], 0, 5Output:
[1,5,0,5]Explanation:
Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.
Input:
[-1,2,3], 1, 2Output:
[1,2,2]Explanation:
Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.
Input:
[5,5], 0, 10Output:
[5,5]Explanation:
Anything under the lower bound is pulled up to it and anything over the upper bound is pulled down to it, leaving in-range values untouched.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
lower ≤ upper