这里有一种实现供参考

# python 3.7
def myfun(A,B):
    a = len(A) #A的行
    b = len(B[0]) #B的列
    c = len(A[0]) #A的列
    d = len(B) #B的行
    
    Final = []
    for e in range (0,a):
        Final.append([])
        for f in range (0,b):
            Final[e].append([])

    for i in range (0,a):
        for j in range (0,b):
            sum = 0
            temp = 0
            m = c # Here c should equals to d
            for h in range (0,m):                  
                temp = A[i][h]*B[h][j]
                sum = sum + temp
            Final[i][j] = sum

    print(Final)
    return Final  

#example
myfun([[1,2,3],[4,2,5],[7,6,1],[5,5,4]],[[2,5,7,1],[2,4,8,16],[12,5,1,1]])
Last modification:January 18th, 2020 at 05:46 pm