Last active
September 8, 2021 19:49
-
-
Save Dharisd/a2ebe1cb75e3439a51303f21dd308c91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
""" basically we try hit m1 hard as i can with based mat multiple op written in `pure' python""" | |
mat_a = [[2,2,2],[2,2,2]] | |
mat_b = [[2,2,1],[2,2,1]] | |
#here we multiple matrices in python like a chad | |
def mat_mulitply(a,b): | |
mat_c = [] | |
for main_index in range(0,len(mat_a)): | |
a_list = mat_a[main_index] | |
nested_array = [] | |
for a in range(0,len(a_list)): | |
val_a = a_list[a] | |
val_b = mat_b[main_index][a] | |
val_c = val_a * val_b | |
nested_array.append(val_c) | |
mat_c.append(nested_array) | |
return mat_c | |
start = time.time() | |
for i in (range(0,1000)): | |
#gen matrices | |
mat_a = [] | |
mat_b = [] | |
for i in range(0,random.randint(1,100)): | |
list_a = [] | |
list_b = [] | |
for i in range(0,random.randint(1,1000)): | |
v_a = random.randint(1,1000) | |
v_b = random.randint(1,1000) | |
#append to inside list | |
list_a.append(v_a) | |
list_b.append(v_b) | |
#append to main array | |
mat_a.append(list_a) | |
mat_b.append(list_b) | |
result = mat_mulitply(mat_a,mat_b) | |
end = time.time() | |
print(end - start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment