Skip to content

Instantly share code, notes, and snippets.

@Steboss89
Created October 14, 2022 15:20
Show Gist options
  • Save Steboss89/54961353130158ecb659d8e0ab0f2508 to your computer and use it in GitHub Desktop.
Save Steboss89/54961353130158ecb659d8e0ab0f2508 to your computer and use it in GitHub Desktop.
Simple matrix multiplication in Python
def matmul(mat1, mat2, mat3):
r""" Function to multiply mat1 and mat2
returns mat3
Parameters
---------
mat1: np.array, matrix A
mat2: np.array, matrix B
mat3: np.array, empty matrix C
Return
------
mat3: np.array, matmul between A & B
"""
for i in range(mat1.shape):
for j in range(mat2.shape):
mat3[i][j] = 0.0
for k in range(mat3.shape):
mat3[i][j] += mat1[i][k]*mat2[k][j]
return mat3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment