Normalize Rows to Unit Length
mediumnumpy_linalgImplement normalize_rows(X).
Given a 2D array X of shape (m, n), return an array of the same shape
where each row is scaled to unit L2 norm (row / ||row||). Assume no
row is all zeros. Vectorize with broadcasting — no for/while loops.
Constraints
- no scipy, sklearn
- no for/while loops
Your solution
Edit normalize_rows and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
np.linalg.norm(X, axis=1, keepdims=True) gives per-row L2 norms to divide by.