I need to find the roots of a function. I am currently using scipy.optimize.fsolve

    def f(z): 
        return ((1-2*z)*np.exp(-d/z))/(((1-z)**(2+d))*(z**(2-d)))
        # d is a constant ndarray of shape(300000,)
        # hence f(z) is an ndarray of shape (300000,)

    def trap(func,a,b,num): #trapezoidal approach to integration
        return np.dot(dx,f12)/2.0
        #also returns an array of shape (300000,)

    def integral(p):
        return trap(f,0,p,1000)

    root= fsolve(f,0.75) # 0.75 because the answer should lie in (0.5,1)

The issue is that I was expecting fsolve to return an array in line with returns of functions f and trap. However, somehow I am only getting a array of shape (1,)

  • $\begingroup$ While the problem you're attempting to solve is based in computational science, the question is strictly on Python programming and thus off-topic here. $\endgroup$ Nov 1 '16 at 4:15