這是結果:
這是Python程式:
def isMatrixMultiply(A,B):
N1 = len(A[0])
N2 = len(B)
if (N1 == N2):
OK = True
else:
OK = False
return OK
def MatrixMultiply(A,B):
M = len(A)
N1 = len(A[0])
N2 = len(B)
P = len(B[0])
if (N1 == N2):
N = N1
for i in range(M):
for k in range(P):
Temp = 0
for j in range(N):
Temp = Temp + A[i][j]*B[j][k]
C[i][k] = Temp
return C
A = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
B = [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15]]
C = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
OK = isMatrixMultiply(A,B)
if (OK):
C = MatrixMultiply(A,B)
for i in range(len(C)):
for j in range(len(C[0])):
print(C[i][j],end='\t')
print(
沒有留言:
張貼留言