Data PreprocessingIntro
Z-score Standardization
~10 mincode completion
Implement z_score_standardize(X). Assume the standard deviation is nonzero.
Examples
Symmetric array: mean=0, std=2
- Input
- z_score_standardize([-3, -1, 0, 1, 3])
- Output
- [-1.5, -0.5, 0, 0.5, 1.5]
3-element array: known z-scores
- Input
- z_score_standardize([10, 20, 30])
- Output
- [-1.22474, 0, 1.22474]
Hints
Hint 1
Work directly with the arguments X and return the result rather than printing it.
Hint 2
Watch for this: divided by variance not std.
Requirements
X: NumPy array. Guaranteed std(X) != 0.Return Array of same shape with mean ≈ 0 and std ≈ 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 z_score_standardize(X: np.ndarray) -> np.ndarray:
"""
Standardize X to zero mean and unit variance.
Args:
X: NumPy array. Guaranteed std(X) != 0.
Returns:
Array of same shape with mean ≈ 0 and std ≈ 1.
"""
# YOUR CODE HERE
pass