Advertisement
brainuser5705

matrix multiplication

Feb 28th, 2022
992
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def square_matrix(matrix1, matrix2):
  2.     size = len(matrix1)
  3.  
  4.     product = [
  5.         [0,0],
  6.         [0,0]
  7.     ]
  8.  
  9.     for i in range(size):
  10.         for j in range(size):
  11.             sum = 0
  12.             for k in range(size):
  13.                 sum += matrix1[i][k] * matrix2[k][j]
  14.             product[i][j] = sum
  15.  
  16.     return product
  17.  
  18. print(square_matrix(
  19.     [[1,4],
  20.     [7,5]],
  21.  
  22.     [[6,8],
  23.     [3,2]]
  24. ))
  25.  
Advertisement
RAW Paste Data Copied
Advertisement