Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can utilize kwargs in scipy.optimize.curve_fit() to transmit a parameter that is not undergoing fitting by specifying the parameter name and its value in the form of a dictionary as the keyword arguments. For example, if you want to pass a parameter "p" with a value of 5 without including it in the fitting process, you can use the following code:

import scipy.optimize as optimize

def func(x, a, b, c):
    return a * x ** 2 + b * x + c

xdata = [1, 2, 3, 4, 5]
ydata = [1, 4, 9, 16, 25]

init_guess = [1, 1, 1]

param_dict = {'p': 5}

popt, pcov = optimize.curve_fit(func, xdata, ydata, p0=init_guess, **param_dict)

In the above example, the parameter "p" is not included in the initial guess and is not being fitted. It is transmitted as a keyword argument through the param_dict. The ** before param_dict tells the function to unpack the dictionary and use it as keyword arguments.