Skip to content

Instantly share code, notes, and snippets.

@mikezink
Created November 18, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikezink/0f450f9b6dd2924516bc3d42145ea5c7 to your computer and use it in GitHub Desktop.
Save mikezink/0f450f9b6dd2924516bc3d42145ea5c7 to your computer and use it in GitHub Desktop.
matrix_mult.py
# input two matrices of size n x m
matrix1 = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]
matrix2 = [[5, 8, 1],
[6, 7, 3],
[4, 5, 9]]
res = [[0 for x in range(3)] for y in range(3)]
# explicit for loops
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
# resulted matrix
res[i][j] += matrix1[i][k] * matrix2[k][j]
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment