All problems
Soft Threshold Vector
Problem
Apply the elementwise soft-thresholding operator.
For each component return x - t if x > t, x + t if x < -t, and 0.0 otherwise. An empty list returns [].
Hint
Small magnitudes collapse to zero; larger ones shrink by exactly t.
Test cases
case 1
in: [[1.5,-0.5,3,0.1],1]
expected: [0.5,0,2,0]
case 2
in: [[2,-2],1]
expected: [1,-1]
case 3
in: [[],0.5]
expected: []
case 4
in: [[1,-1],1]
expected: [0,0]
Starter codePython
def soft_threshold_vector(v, t):
# Your code here
pass4 test cases · run your code against them in the editor