Optimisations
Notice how the innermost line 'new_matrix[i][j] += matrix1[i][k]*matrix2[k][j]' executes for 61 per cent of the total time. This means that optimising this one line can immensely boost your execution speed. Hence, I tried the following optimisation: def mult(matrix1, matrix2): # Matrix multiplication if len(matrix1[0]) != len(matrix2):
print 'Matrices must be m*n and n*p to multiply!'
else: new_matrix = matrix(len(matrix1), len(matrix2[0])) new_matrix.zero() for i in range(len(matrix1)):
for j in range(len(matrix2[0])):