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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started