I created a class of matrix with python:
class MatrixOperation:
...
def create_matrix(self):
some function for creation of matrix.
return matrix
def matrix_vector_multiplication(self, x):
mat = self.create_matrix()
return numpy.dot(mat, x)
And:
M = MatrixOperation(...)
x = some set of vector
for i in range(n):
M.matrix_vector_multiplication(x[i])
The problem is, for each iteration, M.matrix_vector_multiplication(x[i]) will recompute mat = self.create_matrix() before calculating numpy.dot(mat, x), that is unnecessary (since it could be computed once at the beginning). How can I avoid this?
Thanks,
create_matrixreturn the matrix, or could it make it an instance attribute?once? by instance? by process like static variable in Java?