I have this function to compute some sort of polynomial:
def pipoly(df,pj):
n=np.size(pj)
p=pj[0]
for j in range(1,n):
p+=pj[j]*df**j
return p
pj
is supposed to be an array that contains the initial guesses of the coefficients of the polynomial; the degree of the polynomial is hence determined by the function itself in the first line. df
is a scalar variable. This function is passed to scipy.optimize's curve_fit
as
parfit,covfig=curve_fit(pipoly,[f-f0[j] for f in f_df[if0[j]:if0[i]]],
pmode_xp[ph][if0[j]:if0[i]],
p0=([pmode0[ph][-1],(pmode_xp[ph][if0[i]]-pmode_xp[ph][if0[j]])/df]))
The first two arguments after the name of the function are arrays (1D slices of 2D arrays), and I have confirmed that they have the same length. The third argument after pipoly
is supposed to be a tuple with the initial guesses for pj
, which I printed out before: [0.4586590267346888, 0.7419930843896957]
. So why is Python complaining that TypeError: pipoly() takes 2 positional arguments but 3 were given
? And if I remove the p0
argument, I'm told that the pj
is considered a scalar and can therefore not have an index. How do I make it clear to pipoly that pj
is to be an array?