Search code examples
pythonoptimizationscipytypeerrorscipy-optimize-minimize

TypeError: tuple indices must be integers or slices, not str scipy.optimize


I tried to use scipy.optimize.minimize. Here is my code:

def rry_fit(gamma, *args):
    data = args['data']
    data.time.shiftted = data.time - gamma 
    rsqr = rry.rry_cal(data)
    return(rsqr)

   minimize(rry_fit, gamma0, args={'data': df}, method='nelder-mead', options={'xtol': 1e-8, 'disp': True})

However, I got error as follow for the data = args['data'] line.

TypeError: tuple indices must be integers or slices, not str

Thank you for your help.


Solution

  • args is a tuple, not a dictionary. either change it from *args to **kwargs or change args["data"] to args[0], where 0 is the number where the data is.