Skip to content Skip to sidebar Skip to footer

Valueerror: The Array Returned By A Function Changed Size Between Calls Scipy.fsolve()

I am trying to use scipy.optimize.fsolve() to solve for x that makes the function equal to zero, but keep getting the error above. My code is: import scipy.optimize as optimize fro

Solution 1:

Okay I figured out how to get fsolve to work for an array of solutions.

It works if I write the whole thing like this:

Rm = []
initial = [10,10,10,10,10,10]
for j in range(len(ratio)):
    f = lambda x : (ratio[j]*gev.cdf(x,gevcombined[j][0],gevcombined[j][1],gevcombined[j][2]))+((1-ratio[j]*gev.cdf(x,gevcombined[j][0],gevcombined[j][1],gevcombined[j][2]))-P
    Rm.append(list(optimize.fsolve(f,initial)))

And my output is:

[[3.37, 4.37, 5.13, 6.43, 7.91, 9.88],[3.41, 4.42, 5.09, 6.13, 7.07, 8.18],[3.49, 4.87, 5.95, 7.51, 8.80, 10.19]]

Solution 2:

the error occures because the shape of initial does not match your variables.

initial = np.ones(len(x))

However I cannot make my head around what your function is doing. it does the trick for me.

Post a Comment for "Valueerror: The Array Returned By A Function Changed Size Between Calls Scipy.fsolve()"