Clip Features to a Range

Beginner
~8 min
code completion

Clipping Features

Real-world data often contains outliers — extreme values that can destabilize model training. One simple defense is clipping: capping values at a minimum and maximum threshold.

NumPy provides this as a single call:

X_clipped = np.clip(X, low, high)

Your task:

Implement clip_features(X, low, high) that clips all values in X to the range [low, high].

Example Tests

Clip negatives and values above 10

Input: {"X":[-5,0,3,7,12],"low":0,"high":10}

Expected: [0,0,3,7,10]

Float bounds

Input: {"X":[1.5,2.5,3.5],"low":2,"high":3}

Expected: [2,2.5,3]

Clip large absolute values

Input: {"X":[100,50,0,-50,-100],"low":-30,"high":30}

Expected: [30,30,0,-30,-30]

Sign in to solve this problem

You can read the full problem statement above. Create a free account to run code in the browser, submit solutions, and track your progress.