0

I'm working with non-linear regression with python and obtained 'popt' and 'pcov' from 'curve_fit' but when I call 'popt' from a function, I receive an error that there is a missing argument.

I don't understand why do I have to use a pointer to call this variable, I thought that with python we don't need to use it.

Here's an example from Scipy documentation:

>>>> popt, pcov = curve_fit(func, xdata, ydata, bounds=(0, [3., 1., 0.5]))
>>>> popt
     array([2.43736712, 1.        , 0.34463856])
>>>> plt.plot(xdata, func(xdata, *popt), 'g--',
 ...          label='fit: a=%5.3f, b=%5.3f, c=%5.3f' % tuple(popt))
CesarAM
  • 21
  • 3
  • 2
    "but when I call 'popt' from a function" What do you mean by this? "I receive an error that there is a missing argument." What is the error? Please show the code **you** wrote, not the code from the scipy docs which works. Then show the exact error you got. – Code-Apprentice Jul 12 '21 at 18:58
  • 2
    There are no pointers in Python. The asterisk * unpacks the list to arguments to the function. (Edit: wrong link removed) – Stefan Jul 12 '21 at 19:15
  • See https://stackoverflow.com/questions/29400146/passing-a-list-of-parameters-into-a-python-function?noredirect=1&lq=1 – Stefan Jul 12 '21 at 19:22
  • In that docs example, `func(x, a, b, c)`. `popt` has 3 elements, so `*popt` expands it to those 3 variables, `a,b,c`. As for your error, you need to show the code and error, at least enough to see whether your use method of calling `func` matches its signature. – hpaulj Jul 12 '21 at 19:40
  • It's not that you dont *need* pointers, rather, **Python doesn't have pointers** – juanpa.arrivillaga Jul 12 '21 at 20:22

0 Answers0