错误:无法使用scipy.misc中的派生函数调用“float”对象

cld4siwp  于 2023-01-30  发布在  其他
关注(0)|答案(1)|浏览(117)

我试图使用Scipi. Misc的导函数找到泰勒级数的系数,但我在Scypy库中不断得到错误。
我的代码:

d_pts = order*2
 if d_pts % 2 == 0: # must be odd and greater than derivative order
   d_pts += 1
 coefficients = []
 for i in range(1, order+1):
   coefficients.append(round((derivative(function, center, n=i, order=d_pts))/math.factorial(i), 5))
 return coefficients

错误消息:

<ipython-input-31-c44b369ecec2> in findCoefficients(function, order, center)
     5   coefficients = []
     6   for i in range(1, order+1):
----> 7     coefficients.append(round((derivative(function, center, n=i, order=d_pts))/math.factorial(i), 5))
     8   return coefficients

/usr/local/lib/python3.8/dist-packages/scipy/misc/common.py in derivative(func, x0, dx, n, args, order)
   142     ho = order >> 1
   143     for k in range(order):
--> 144         val += weights[k]*func(x0+(k-ho)*dx,*args)
   145     return val / prod((dx,)*n,axis=0)
   146 

TypeError: 'float' object is not callable

有人知道怎么修吗?

9fkzdhlc

9fkzdhlc1#

看起来您传递的不是函数而是浮点值。请确保function不是浮点值而是函数。
另外,请注意,不建议使用导数函数。https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html

相关问题