I have two simple arrays in Python and I would like to minimize the sumproduct of these arrays with respect to given target value by changing the values in the first array. Here is an example:
import numpy as np
from scipy.optimize import fmin
def func2(params):
a, b, c = params
arr1 = [a, b, c]
arr2 = [150, 200, 230]
res = sum(np.multiply(arr1, arr2))
tar = 2
error = res - tar
return error
initial_guess = [0.0025, 0.0030, 0.0035]
finarr = fmin(func2, initial_guess)
print(finarr)
The code above runs but I receive wrong results because the numbers in first array should be ~ 0.0027, 0.0033 and 0.0040. I would be grateful if someone can help me. Thank you.