Data PreprocessingIntro
Min-Max Normalization
~10 mincode completion
Implement min_max_normalize(X) that scales all values to [0, 1]. Assume .
Examples
Simple 3-element array
- Input
- min_max_normalize([0, 5, 10])
- Output
- [0, 0.5, 1]
Negative to positive range
- Input
- min_max_normalize([-10, 0, 10])
- Output
- [0, 0.5, 1]
5-element array
- Input
- min_max_normalize([1, 2, 3, 4, 5])
- Output
- [0, 0.25, 0.5, 0.75, 1]
Hints
Hint 1
Work directly with the arguments X and return the result rather than printing it.
Hint 2
A common slip here: subtracted mean instead of min.
Requirements
X: NumPy array (any shape). Guaranteed X.max() != X.min().Return Array of same shape with values in [0, 1].
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~10 min
••••••••••••
6 employers weight this skill
2 AI product companies, 2 health and bio companies, 1 defense company, 1 enterprise vendor. Top match scores 75.
Python
import numpy as np
def min_max_normalize(X: np.ndarray) -> np.ndarray:
"""
Scale X to the range [0, 1].
Args:
X: NumPy array (any shape). Guaranteed X.max() != X.min().
Returns:
Array of same shape with values in [0, 1].
"""
# YOUR CODE HERE
pass