Challenge: L2 Normalization and Norm Comparison
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 4
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 5.26
Challenge: L2 Normalization and Norm Comparison
Stryg for at vise menuen
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 2. Kapitel 4
single