Pythonアルゴリズム-108(プログラマ)マトリクスの乗算



コード#コード#

def solution(arr1, arr2):
    answer = []
    for i in range(len(arr1)):
        lst=[]
        for j in range(len(arr2[0])):
            part_sum=0
            for k in range(len(arr1[i])):
                part_sum+=arr1[i][k]*arr2[k][j]
            lst.append(part_sum)
        answer.append(lst)
    return answer

他人の解答

def productMatrix(A, B):
    return [[sum(a*b for a, b in zip(A_row,B_col)) for B_col in zip(*B)] for A_row in A]