def changeRowColumn(matrix, row, col) :
(rows, cols) = (len(matrix), len(matrix[0]))
# -1 = different from the existing zeros
for j in range(cols):
if (matrix[row][j] != 0) :
matrix[row][j] = -1
for i in range(rows):
if (matrix[i][col] != 0) :
matrix[i][col] = -1
def changeBinaryMatrix(matrix) :
if not matrix or not len(matrix):
return
(rows, cols) = (len(matrix), len(matrix[0]))
for i in range(rows):
for j in range(cols):
if matrix[i][j] == 0:
changeRowColumn(matrix, i, j)
for i in range(rows):
for j in range(cols):
if (matrix[i][j] == -1) :
matrix[i][j] = 0
def printMatrix( matrix) :
(rows, cols) = (len(matrix), len(matrix[0]))
for i in range(rows):
for j in range(cols):
print(str(matrix[i][j]) + " ", end ="")
print("\n", end ="")
# for row in matrix:
# print(row)
matrix = [[1, 1, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 1, 0, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 1, 1]]
changeBinaryMatrix(matrix)
printMatrix(matrix)
'''
run:
0 0 0 0 0 0
1 0 0 1 1 1
0 0 0 0 0 0
1 0 0 1 1 1
0 0 0 0 0 0
'''