Back to Practice
#0199
Standardize Columns
MediumNumPy25 min20 XP
Problem
Given a 2D NumPy array X, return column-wise z-scores using population standard deviation.
Why This Matters
Standardization is used before distance-based models, gradient methods, PCA, and many regularized models.
Function Signature
def standardize_columns(X):
Examples
Example 1
Input[[1, 10], [2, 20], [3, 30]]
Output[[-1.2247, -1.2247], [0.0, 0.0], [1.2247, 1.2247]]
Each column is transformed using its own mean and standard deviation.
Constraints
- Return the exact requested result.
- Handle common edge cases.
- Keep the solution readable before optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[[1, 10], [2, 20], [3, 30]]
Expected[[-1.2247, -1.2247], [0.0, 0.0], [1.2247, 1.2247]]
Each column is transformed using its own mean and standard deviation.
Hidden Test Categories
negative valuesfloat inputsmore rows than columns