You are viewing a single comment's thread. Return to all comments →
# def matrixmultiplicaton(A, B, N):
Seems like cookies are disabled on this browser, please enable them to open this website
Dot and Cross
You are viewing a single comment's thread. Return to all comments →
# def matrixmultiplicaton(A, B, N):
result= [[0]*N for num in range(N)]
for i in range(N):
for j in range(N):
for k in range(N):
result[i][j] += A[i][k]*B[k][j]
return result
if name == 'main':
N=int(input())
A=[]
for num in range(N):
row=list(map(int, input(). strip(). split()))
A.append(row)
B=[]
for num in range(N):
row=list(map(int, input(). strip(). split()))
B.append(row)
result=matrixmultiplicaton(A, B, N)
print("[", end="")
for i, row in enumerate(result):
print("[" + " ".join(map(str, row)) + "]", end="")
if i==0:
print()
if i < len(result) - 1:
print("", end="")
print("]")