 # Question & Answer: Current code works but I want the code in the comments to work where user enters rows, columns and contents of array the question i….. Current code works but I want the code in the comments to work where user enters rows, columns and contents of array the question is to write an algorithm that if an element in an m*n matrix is 0, its entire row and column is set to 0

Algorithm with example:

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Current code works but I want the code in the comments to work where user enters rows, columns and contents of array the question i…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Suppose,

arr = [[1, 0, 1, 1, 0],
[0, 1, 1, 1, 0],
[1, 1, 1, 1, 1],
[1, 0, 1, 1, 1],
[1, 1, 1, 1, 1]]

Nob = len(arr)

### pass 1

# 1 rst line/column
tt = 1
for uu in range(Nob):
tt &= arr[uu]

l = 1
for uu in range(1,Nob):
l &= arr[uu]

# other line/cols
# use line1, col1 to keep only those with 1
for uu in range(1,Nob):
for qq in range(1,Nob):
if arr[uu][qq] == 0:
arr[qq] = 0
arr[uu] = 0
else:
arr[uu][qq] = 0

### pass 2

# if line1 and col1 are ones: it is 1
for uu in range(1,Nob):
for qq in range(1,Nob):
if arr[uu] & arr[qq]:
arr[uu][qq] = 1

# 1rst row and col: reset if 0
if l == 0:
for uu in range(Nob):
arr [uu] = 0

if tt == 0:
for qq in range(1,Nob):
arr [qq] = 0

print(arr)