Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-013

L1 Vector Norm

Problem

Compute the L1 (Manhattan) norm of a vector v: the sum of the absolute values of its components.

||v||_1 = sum(|v[i]|).

Hint

Use the built-in abs and sum.

Test cases

case 1
in: [[3,-4]]
expected: 7
case 2
in: [[1,2,3]]
expected: 6
case 3
in: [[0,0,0]]
expected: 0
case 4
in: [[-1.5,2.5,-3]]
expected: 7
Starter codePython
def l1_norm(v):
    # Your code here
    pass

4 test cases · run your code against them in the editor