Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Projecting a vector onto box constraints is a common step in constrained optimization and gradient-based methods. In this problem, you’ll implement the projection operator that “clips” each coordinate into a valid interval.
Implement the function
Rules:
x[i] independently into the interval [lower[i], upper[i]].Output:
| Argument | Type |
|---|---|
| x | np.ndarray |
| lower | np.ndarray |
| upper | np.ndarray |
| Return Name | Type |
|---|---|
| value | np.ndarray |
Use NumPy; no SciPy or helpers.
Return NumPy array.
Do not mutate inputs in-place.
Use np.clip(x, lower, upper) for a direct vectorized solution.
Alternatively, np.minimum(np.maximum(x, lower), upper) achieves the same result.