NumPy reduce with an updating parameter

68 Views Asked by At

Let X and theta respectively be a (m,k) and (k,1) shaped ndarray. Consider the following code

res = np.zeros(theta.shape)
for x_i in X:
    res +=  x_i @ theta

The for cycle could be rewritten as res = (X @ theta).sum(). Now consider this version

for x_i in X:
    theta += x_i @ theta

is there a way to rewrite it without the for cycle, since the theta parameter gets updated at every iteration? Maybe using numpy.ufunc.reduce?

0

There are 0 best solutions below