Skip to content
DeepForgeby svx
All problems
EasyCalculusca-210

Proximal Operator of L2

Problem

The proximal operator of the L2 norm is block soft-thresholding:

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

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

Hint

Unlike L1, the L2 prox shrinks the whole vector without zeroing individual entries.

Test cases

case 1
in: [[3,4],1]
expected: [2.4000000000000004,3.2]
case 2
in: [[0,0],1]
expected: [0,0]
case 3
in: [[1,0],2]
expected: [0,0]
case 4
in: [[6,8],10]
expected: [0,0]
case 5
in: [[1,0],0.5]
expected: [0.5,0]
Starter codePython
def prox_l2(values, lam):
    # Your code here
    pass

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