All problems
Clip Matrix
Problem
Clip every entry of matrix A to the interval [lo, hi].
Entries below lo become lo, entries above hi become hi, and entries inside are unchanged.
Hint
Clamp each entry with min(hi, max(lo, x)).
Test cases
case 1
in: [[[1,5],[10,2]],2,8]
expected: [[2,5],[8,2]]
case 2
in: [[[0,0]],-1,1]
expected: [[0,0]]
case 3
in: [[[-5,5]],0,0]
expected: [[0,0]]
case 4
in: [[[1.5,-2.5],[3,0]],-1,2]
expected: [[1.5,-1],[2,0]]
Starter codePython
def clip_matrix(A, lo, hi):
# Your code here
pass4 test cases · run your code against them in the editor