Challenge: L2 Normalization and Norm Comparison
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 4
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Suggested prompts:
Can you explain this in simpler terms?
What are the next steps I should take?
Can you provide an example?
Awesome!
Completion rate improved to 5.26
Challenge: L2 Normalization and Norm Comparison
Swipe um das Menü anzuzeigen
Aufgabe
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ösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 2. Kapitel 4
single