Skip to content
DeepForgeby svx
All problems
EasyCalculusca-209

Proximal Operator of L1

Problem

The proximal operator of the L1 norm is elementwise soft-thresholding:

prox(v) = sign(v) * max(|v| - lambda, 0)

Given a list of values and lambda >= 0, return the prox result.

Hint

Soft-thresholding drives small entries exactly to zero, which creates sparsity.

Test cases

case 1
in: [[3,-2],1]
expected: [2,-1]
case 2
in: [[0.5],1]
expected: [0]
case 3
in: [[1,2,3],0]
expected: [1,2,3]
case 4
in: [[-0.5,0.5],0.5]
expected: [0,0]
Starter codePython
def prox_l1(values, lam):
    # Your code here
    pass

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