c-programming

Simple C programs
git clone git://git.laack.co/c-programming.git
Log | Files | Refs

mat-mul.py (720B)


      1 import random
      2 
      3 x = 400 # rows
      4 y = 400 # columns
      5 
      6 
      7 def init(x,y):
      8     first = []
      9     for _ in range(0,x):
     10         current = []
     11         for _ in range(0,y):
     12             current.append(random.random())
     13         first.append(current)
     14     return first
     15 
     16 first = init(x,y)
     17 second = init(x,y)
     18 
     19 def dp(first, second):
     20     s = 0
     21     for i in range(0, len(first)):
     22         s += first[i] * second[i]
     23     return s
     24 
     25 
     26 res = []
     27 
     28 for row_index in range(0,x):
     29     current_row = []
     30     for col_index in range(0,y):
     31 
     32         row = first[row_index]
     33 
     34         column = []
     35         for i in range(len(second)):
     36             column.append(second[i][col_index])
     37 
     38 
     39         current_row.append( dp(row,column))
     40 
     41     res.append(current_row)
     42 
     43 print(res)