[Python] supply extra parameter as function argument for scipy optimize curve_fit

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am defining a piecewise function for some data,

    def fit_jt(x, e1, e2, n1, E1, E2, N1, N2):
    a = 1.3
    return np.piecewise(x, [x <= a, x > a], [
    lambda x: 1 / e1 +
    (1 - np.float128(np.exp(-e2 * x / n1))) / e2, lambda x: 1 / E1 +
    (1 - np.float128(np.exp(-E2 * x / N1))) / E2 + x / N2
    ])


    which is called in main as:

    popt_jt, pcov_jt = optimize.curve_fit(fit_jt,
    time.values,
    jt.values,
    method='trf')


    Now, the problem here is the a is hardcoded in the function fit_jt. Is it possible to supply the value of a from the main (without making a lot of changes)?

    Continue reading...

Compartilhe esta Página