I'm trying to vectorize a function that consist of a loop.
The original function is:
def error(X, Y, m, c):
total = 0
for i in range(20):
total += (Y[i]-(m*X[i]+c))**2
return total
I've tried the following but It doesn't work:
def error(X, Y, m, c):
errorVector = np.array([(y-(m*x+c))**2 for (x,y) in (X,Y)])
total = errorVector.sum()
return total
How can I vectorize the function?
X,Y,m,c?