Why am I getting TypeError: unsupported operand types for -: 'float' and 'function'?
Question: This is my code:

    
    
    def concfunction(time,k):
        return 0.1*exp((-k)*(time))
    
    from scipy.optimize import curve_fit
    curve_fit(concfunction,time,k,p0=[10])
    

Where I've already got arrays for time and concentration, and I want to find
`k` using `curve_fit`.

I get the following error:

    
    
    TypeError                                 Traceback (most recent call last)
    <ipython-input-48-48cc519b697a> in <module>()
    ----> 1 curve_fit(concfunction,time,k,p0=[10])
    
    C:\Users\Daisy\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in curve_fit(f, xdata, ydata, p0, sigma, absolute_sigma, check_finite, **kw)
    579     # Remove full_output from kw, otherwise we're passing it in twice.
    580     return_full = kw.pop('full_output', False)
    --> 581     res = leastsq(func, p0, args=args, full_output=1, **kw)
    582     (popt, pcov, infodict, errmsg, ier) = res
    583 
    
    C:\Users\Daisy\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in leastsq(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)
    369     if not isinstance(args, tuple):
    370         args = (args,)
    --> 371     shape, dtype = _check_func('leastsq', 'func', func, x0, args, n)
    372     m = shape[0]
    373     if n > m:
    
    C:\Users\Daisy\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in _check_func(checker, argname, thefunc, x0, args, numinputs, output_shape)
     18 def _check_func(checker, argname, thefunc, x0, args, numinputs,
     19                 output_shape=None):
    ---> 20     res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
     21     if (output_shape is not None) and (shape(res) != output_shape):
     22         if (output_shape[0] != 1):
    
    C:\Users\Daisy\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in _general_function(params, xdata, ydata, function)
    445 
    446 def _general_function(params, xdata, ydata, function):
    --> 447     return function(xdata, *params) - ydata
    448 
    449 
    
    TypeError: unsupported operand type(s) for -: 'float' and 'function'
    

Can anyone please help me resolve this?


Answer: If we assume `concfunction` returns float then time has to by of type:
function. What imports are you using? How are declared time and k? I will
guess time is a function from import or declared as function.

