Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Vector Norms and Magnitude | Section
Mastering Linear Algebra Fundamentals

bookVector Norms and Magnitude

Свайпніть щоб показати меню

Understanding the size or "length" of a vector is essential in linear algebra and data science. The most common way to measure a vector's magnitude is the Euclidean norm, also called the L2 norm. For a vector v=[v1,v2,...,vn]v = [v₁, v₂, ..., vₙ], the L2 norm calculates the straight-line distance from the origin to the point represented by the vector in n-dimensional space. The formula for the L2 norm is:

v2=v12+v22+...+vn2||v||₂ = \sqrt{v₁² + v₂² + ... + vₙ²}

Another important norm is the L1 norm, also known as the Manhattan norm. This norm sums the absolute values of the vector's components:

v1=v1+v2+...+vn||v||₁ = |v₁| + |v₂| + ... + |vₙ|

These norms are widely used in data science. The L2 norm is often used for measuring Euclidean distance and in regularization (like Ridge regression), while the L1 norm is used in scenarios where sparsity is important (like Lasso regression).

123456789101112
import numpy as np # Define a vector v = np.array([3, -4, 1]) # Compute the L2 (Euclidean) norm l2_norm = np.sqrt(np.sum(v ** 2)) print("L2 norm:", l2_norm) # Compute the L1 norm l1_norm = np.sum(np.abs(v)) print("L1 norm:", l1_norm)
copy

In the code above, you define a vector v with three components. To find the L2 norm, you square each component, sum them, and then take the square root. This gives you the Euclidean distance from the origin to the point [3, -4, 1]. The L1 norm is calculated by summing the absolute values of each component, which measures the total "taxicab" or "Manhattan" distance.

The L2 norm is sensitive to large values in any component, as squaring amplifies their effect. This is suitable when you want to penalize large deviations strongly or measure straight-line distances. The L1 norm treats each component equally, making it robust to outliers and useful when you want to encourage sparsity in solutions, such as in feature selection for machine learning models. Choosing between these norms depends on your specific use case and the properties you want to emphasize in your data analysis or model.

question mark

Which statement best describes the difference between the L1 and L2 norms of a vector?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 3
some-alt