Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-151

Threshold Matrix

Problem

Keep entries of A that are strictly greater than the threshold t, and replace all others with 0.

Return the thresholded matrix.

Hint

The comparison is strict: entries equal to t become 0.

Test cases

case 1
in: [[[1,2],[3,4]],2]
expected: [[0,0],[3,4]]
case 2
in: [[[-1,0],[1,2]],0]
expected: [[0,0],[1,2]]
case 3
in: [[[5]],10]
expected: [[0]]
case 4
in: [[[1.5,2.5]],2]
expected: [[0,2.5]]
Starter codePython
def threshold_matrix(A, t):
    # Your code here
    pass

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