Skip to content
DeepForgeby svx
All problems
MediumOptimizationop-323

Hard Threshold Scalar Value

Problem

The hard threshold operator keeps v when |v| > t and returns zero otherwise.

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

Hint

Strict inequality: equality maps to zero.

Test cases

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

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