Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions