Challenge: L2 Normalization and Norm Comparison
Taak
Swipe to start coding
You are given a NumPy array X of shape (n_samples, n_features).
Your goal is to L2-normalize each row (sample) and compare norms before and after normalization using np.linalg.norm.
- Compute row-wise L2 norms as a column vector
row_normswith shape(n_samples, 1)usingnp.linalg.norm(..., axis=1, keepdims=True). - Create
X_l2by dividing each row ofXby its L2 norm via broadcasting. - Compute
norms_beforeandnorms_afteras 1D arrays (shape(n_samples,)) withnp.linalg.norm(..., axis=1). - Assume there are no zero rows in
X. Do not modifyXin place. Use vectorized NumPy operations.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 4
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 5.26
Challenge: L2 Normalization and Norm Comparison
Veeg om het menu te tonen
Taak
Swipe to start coding
You are given a NumPy array X of shape (n_samples, n_features).
Your goal is to L2-normalize each row (sample) and compare norms before and after normalization using np.linalg.norm.
- Compute row-wise L2 norms as a column vector
row_normswith shape(n_samples, 1)usingnp.linalg.norm(..., axis=1, keepdims=True). - Create
X_l2by dividing each row ofXby its L2 norm via broadcasting. - Compute
norms_beforeandnorms_afteras 1D arrays (shape(n_samples,)) withnp.linalg.norm(..., axis=1). - Assume there are no zero rows in
X. Do not modifyXin place. Use vectorized NumPy operations.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 2. Hoofdstuk 4
single