Set Matrix Zeros



質問する
に答える
nRow = len(matrix)
nCol = len(matrix[0])
# 0인 곳의 인덱스 찾기
zeroIndices = []
for row, li in enumerate(matrix):
for col, el in enumerate(li):
if el == 0:
zeroIndices.append([row, col])
# 인덱스 이용해서 행과 열의 값 변경
for row, col in zeroIndices:
# 행 값 변경
for c in range(nCol):
matrix[row][c] = 0
# 열 값 변경
for r in range(nRow):
matrix[r][col] = 0
return None
結果
1 t成功!
Reference
この問題について(Set Matrix Zeros), 我々は、より多くの情報をここで見つけました
https://velog.io/@twinklesu914/Set-Matrix-Zeros
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
Reference
この問題について(Set Matrix Zeros), 我々は、より多くの情報をここで見つけました https://velog.io/@twinklesu914/Set-Matrix-Zerosテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol