2차원 행렬 arr1과 arr2를 입력받아, arr1에 arr2를 곱한 결과를 반환하는 함수, solution을 완성해주세요.
arr1 | arr2 | return |
---|---|---|
[[1, 4], [3, 2], [4, 1]] | [[3, 3], [3, 3]] | [[15, 15], [15, 15], [15, 15]] |
[[2, 3, 2], [4, 2, 4], [3, 1, 4]] | [[5, 4, 3], [2, 4, 1], [3, 1, 1]] | [[22, 22, 11], [36, 28, 18], [29, 20, 14]] |
def solution(arr1, arr2):
a1=len(arr1)
a2=len(arr2[0])
answer = [[0]*a2 for _ in range(a1)]
for i in range(a1):
for j in range(a2):
for k in range(len(arr2)):
answer[i][j]+=arr1[i][k]*arr2[k][j]
return answer
문제 출처 : https://programmers.co.kr/learn/courses/30/lessons/12949