Created
November 6, 2011 23:20
-
-
Save sputnikus/1343766 to your computer and use it in GitHub Desktop.
Too lazy for serious math...
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
from pprint import pprint | |
def zero(m, n): | |
new_matrix = [[0 for row in range(n)] for col in range(m)] | |
return new_matrix | |
def mult(matrix1, matrix2): | |
if len(matrix1[0]) != len(matrix2): | |
print('Matrices must be m*n and n*p to multiply!') | |
else: | |
new_matrix = zero(len(matrix1), len(matrix2[0])) | |
for i in range(len(matrix1)): | |
for j in range(len(matrix2[0])): | |
for k in range(len(matrix2)): | |
new_matrix[i][j] += matrix1[i][k] * matrix2[k][j] | |
return new_matrix | |
MATRIX = [[0, 1, 1, 0, 1, 0], | |
[1, 0, 1, 1, 1, 1], | |
[1, 1, 0, 0, 1, 1], | |
[0, 1, 0, 0, 1, 1], | |
[1, 1, 1, 1, 0, 1], | |
[0, 1, 1, 1, 1, 0]] | |
if __name__ == "__main__": | |
semi = MATRIX | |
for _ in range(5): | |
pprint(semi) | |
semi = mult(semi, MATRIX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment