행렬의 곱셈
2차원 행렬 arr1과 arr2를 입력받아, arr1에 arr2를 곱한 결과를 반환하는 함수, solution을 완성해주세요.
생각보다 헷갈림
과거
def solution(arr1, arr2):
answer = [[0 for _ in range(len(arr2[0]))] for _ in range(len(arr1))]
print(answer)
for i in range(len(arr1)):
for j in range(len(arr2[0])):
for k in range(len(arr2)):
answer[i][j] += arr1[i][k] * arr2[k][j]
return answer
현재
def solution(arr1, arr2):
row = len(arr1)
col = len(arr2[0])
answer = [ [0 for i in range(col)] for i in range(row)]
for r in range(row):
for c in range(col):
for k in range(len(arr2)):
answer[r][c] += arr1[r][k] * arr2[k][c]
return answer