Created
October 14, 2022 15:20
-
-
Save Steboss89/54961353130158ecb659d8e0ab0f2508 to your computer and use it in GitHub Desktop.
Simple matrix multiplication in Python
This file contains hidden or 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
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