Question: Write a function that takes a matrix (2D list with numeric values) and a threshold (numeric type), and returns the binarized matrix. To binarize a

Write a function that takes a matrix (2D list with numeric values) and a threshold (numeric type), and returns the binarized matrix. To binarize a matrix, each element smaller than the threshold is changed to 0, and other elements (>= threshold) are changed to 1.

Requirement: You should NOT use loops and list comprehension for this question. Instead, use lambda functions, map, or filter . There are no restrictions on the number of lines, but our solution is one line.

def binarize_matrix(matrix, threshold): """ A function that takes a matrix (2D list with numeric values) and a threshold, and returns the binarized matrix. To binarize a matrix, each element smaller than the threshold is changed to 0, and other elements are changed to 1.

You should NOT use loops and list comprehension for this question.

>>> binarize_matrix([[1, -2, -3], [-4, 5, -6], [-7, -8, 9]], 0) [[1, 0, 0], [0, 1, 0], [0, 0, 1]] >>> binarize_matrix([[-0.6, -1.2], [-7, -3.5]], -5.5) [[1, 1], [0, 1]] >>> binarize_matrix([[12.5, 4.8, -3], [-9, 1.2, 4.2], [0.1, 2.2, 1]], 20) [[0, 0, 0], [0, 0, 0], [0, 0, 0]] """ # YOUR CODE GOES HERE #

Thanks in advance!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!