For doing repeated operations in numpy/scipy, there's a lot of overhead because most operation return a new object.
For example
for i in range(100):
x = A*x
I would like to avoid this by passing a reference to the operation, like you would in C
for i in range(100):
np.dot(A,x,x_new) #x_new would now store the result of the multiplication
x,x_new = x_new,x
Is there any way to do this? I would like this not for just mutiplication but all operations that return a matrix or a vector.
outparameter, especially theufuncones. And basic operators have versions like+=,*=.ufuncsalso havereduceandaccumulatemethods to handle repeated actions.np.dotalready does exactly this - the third argument tonp.dotis theout=parameter, sox_newwill be filled in place with the result ofnp.dot(A, x)np.dot(np.linalg.matrix_power(A, 100), x).