給定兩矩陣𝐴,𝐵,請輸出兩矩陣相乘的結果。測資中的兩矩陣必可相乘。
a=[] a=[int(x) for x in input().split()] ina=[] for i in range(a[0]): temp=[int(x) for x in input().split()] ina.append(temp) inb=[] for i in range(a[2]): temp=[int(x) for x in input().split()] inb.append(temp)
#先建立儲存相乘結果的串列 outm outm=[[0]*a[0] for _ in range(a[3])] for i in range(a[0]): for j in range(a[3]): outm[i][j]=0 for k in range(a[1]): outm[i][j]=outm[i][j]+ina[i][k]*inb[k][j] print(outm)