Skip to content
DeepForgeby svx
All problems
EasyCalculusca-212

Proximal Operator of Box

Problem

The proximal operator of the indicator function of the box [lo, hi] is the projection onto that box, which is elementwise clipping.

Given a list of values and bounds lo <= hi, return [max(lo, min(hi, v)) for each v].

Hint

Projection onto a box clips every coordinate independently.

Test cases

case 1
in: [[-2,0.5,3],0,1]
expected: [0,0.5,1]
case 2
in: [[5,5],-1,1]
expected: [1,1]
case 3
in: [[0.2,0.8],0.3,0.7]
expected: [0.3,0.7]
case 4
in: [[],0,1]
expected: []
Starter codePython
def prox_box(values, lo, hi):
    # Your code here
    pass

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