Neural Mastery
← Practice
Euclidean and Manhattan Vector Normseasy

Euclidean and Manhattan Vector Norms

easy Math for ML 10-15 min

NumPy allowed · plain Python earns 10 bonus points

Linear algebra step 1/4

A vector transforms

Matrix multiplication is the first computation behind every model.
Open lesson →
01vector
02matrix
03transform
04result
[2, −1] × [[1, 2], [−.5, 1]] = [0, −2]

Computed matrix × vector transformation

Compute L1, L2, and L-infinity norms of an n-dimensional vector.

Related Skills

Task

Implement vector_norms(v): calculate the Manhattan norm (sum of absolute values), Euclidean norm (square root of sum of squares), and Chebyshev/L-infinity norm (maximum absolute value). Return a dict {"l1": float, "l2": float, "linf": float} with all values rounded to 4 decimal places.

Function Signature

vector_norms(v: list[float]) -> dict[str, float]

Examples

Example 1: Standard Vector
Input: v = [3, -4]
Output: {'l1': 7, 'l2': 5, 'linf': 4}
Explanation: 3-4 triangle vector norms.
Example 2: 3D Positive Vector
Input: v = [1, 2, 2]
Output: {'l1': 5, 'l2': 3, 'linf': 2}
Explanation: 3D unit integer norms.

Constraints

  • Vectors have length 1 to 1,000.
  • Elements are real numbers.
Python3Saved ✓
def vector_norms(v: list[float]) -> dict[str, float]:
"""Compute L1, L2, and Linf norms of vector v.
Return {'l1': float, 'l2': float, 'linf': float} rounded to 4 decimals."""
# Your implementation here
pass

Case 1: Standard Vector
Input: v = [3, -4]
Expected: {'l1': 7, 'l2': 5, 'linf': 4}
Case 2: 3D Positive Vector
Input: v = [1, 2, 2]
Expected: {'l1': 5, 'l2': 3, 'linf': 2}