Guest User

Untitled

a guest
Apr 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # Matrix multiplication algorithm by spel3o
  2. def show_tell(a,b):
  3.     display(matrix_multiply(a,b))
  4.  
  5. def display(matrix):
  6.     for i in range(len(matrix)):
  7.         print matrix[i]
  8.  
  9. def maketrix(m,n):
  10.     result = [[0 for row in range(n)] for col in range(m)]
  11.     return result
  12.  
  13. def matrix_multiply(a,b):
  14.     if len(a[0]) != len(b):
  15.         print 'Matrix multiplication not possible'
  16.     else:
  17.         n = len(a)
  18.         m = len(a[0])
  19.         p = len(b[0])
  20.         result = maketrix(n,p)
  21.         for pony in range(p):
  22.             for murk in range(m):
  23.                 for nope in range(n):
  24.                     result[nope][pony] += a[nope][murk]*b[murk][pony]
  25.         return result
Add Comment
Please, Sign In to add comment