Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-322

Soft Threshold Scalar Value

Problem

The scalar soft threshold operator is sign(v) * max(|v| - t, 0).

Given v and t >= 0, return the thresholded value.

Hint

Values within the threshold band collapse to zero.

Test cases

case 1
in: [1.5,0.5]
expected: 1
case 2
in: [-3,1]
expected: -2
case 3
in: [0.25,0.5]
expected: 0
Starter codePython
def soft_threshold_scalar_value(v, t):
    # Your code here
    pass

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