In Python, Given the 2D list below, convert all values to 255 if they are above a threshold or to 0 if they are below. The threshold value is given as input by the user a =[[77,68,86,73],[96,87,89,81],[70,90,86,81]]
In Python, Given the 2D list below, convert all values to 255 if they are above a threshold or to 0
if they are below. The threshold value is given as input by the user
a =[[77,68,86,73],[96,87,89,81],[70,90,86,81]]
![](/static/compass_v2/shared-icons/check-mark.png)
Code
a =[[77,68,86,73],[96,87,89,81],[70,90,86,81]] # 2d array
#printing the orignal matrix
print("Orignal matrix is:")
for i in range(len(a)):
for j in range(len(a[i])):
print(a[i][j]," ",end='')
print('\n')
n= int(input("Enter a threshold value: ")) #user input threshold value
#setting value to threshold
for i in range(len(a)):
for j in range(len(a[i])):
if a[i][j]>n:
a[i][j]=255
else:
a[i][j]=0
print("New matrix is:")
#printing the changed matrix
for i in range(len(a)):
for j in range(len(a[i])):
print(a[i][j]," ",end='')
print('\n')
Step by step
Solved in 2 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)