You are viewing a single comment's thread. Return to all comments →
Using Built-ins:
import numpy as np N= int(input()) A = [list(map(int, input().split())) for i in range(N)] B = [list(map(int, input().split())) for i in range(N)] print(np.matmul(A, B))
Without Using built-ins
import numpy as np N= int(input()) A = [list(map(int, input().split())) for i in range(N)] B = [list(map(int, input().split())) for i in range(N)] final_array =[] for i in range(N): sum_total= [] for j in range(N): sum =0 for k in range(N): sum = sum + (A[i][k] * B[k][j]) sum_total.append(sum) final_array.append(sum_total) print(np.array(final_array)) # For Your Understanding # ------------------------------ # print(A) #[['1', '2'], ['3', '4']] # print(B) #[['1', '2'], ['3', '4']] # i, j, k= 0, 0, 0 1 * 1 = 1 # i, j, k= 0, 0, 1 2 * 3 = 6 # i, j, k= 0, 1, 0 1 * 2 = 2 # i, j, k= 0, 1, 1 2 * 4 = 8 # i, j, k= 1, 0, 0 3 * 1 = 3 # i, j, k= 1, 0, 1 4 * 3 = 12 # i, j, k= 1, 1, 0 3 * 2 = 6 # i, j, k= 1, 1, 1 4 * 4 = 16 # (i[0][0]*j[0][0]) + (i[0][1]*j[1][0]) (i[0][0]*j[0][1]) + (i[0][1]*j[1][1]) ............. # Ex- Matrix A & B # [[1 2] [[1 2] # [3 4]] [3 4]] # Product of A & B # (1*1) + (2*3) (1*2) + (2*4) # (3*1) + (4*3) (3*2) + (4*4) # Result of above Matrix Multiplication # 7 10 # 15 22
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 →
Using Built-ins:
Without Using built-ins