I'm trying to minimize a function w.r.t. a list x0
of shape (30)
, but I got the error:
"invalid index to scalar variable"
In particular my code is like this:
def func(data, x0):
s_i=np.zeros(data.shape[0])
for i in range(data.shape[0]):
x=(data[i][0]+(data[i][1:]*x0).sum())
s_i[i]=x
return (s_i*s_i).sum()-(s_i.sum())**2
x0=np.ones(30)
x0=list(x0)
out=scipy.optimize.minimize(func, x0, args=(data), method='Nelder-Mead', options={'maxiter':100000, 'disp': True})
in which data is a numpy array of shape (N,31)
and data[i][1:]*x0
is the part which raises the error. How can I solve this?