我正在使用 python 对我的代码进行数据分析。我目前正在尝试调试一些东西,所以我将一些可能无效的数据放入我的 python 代码中。一条利用curve_fit
给我的线TypeError
TypeError: array cannot be safely cast to required type
Traceback (most recent call last):
File "makeStuffUnHR.py", line 405, in <module>
FT = plotFT(FT,A)
File "makeStuffUnHR.py", line 325, in plotFT
line,pars = fitFTsurfaceTension(FTRange2,fty,a)
File "/home/yotam/Applications/Process/dataHandler.py", line 75, in fitFTsurfaceTension
popt, pcov = curve_fit(FTfuncSurface,x,log(y))
File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 426, in curve_fit
res = leastsq(func, p0, args=args, full_output=1, **kw)
File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 283, in leastsq
gtol, maxfev, epsfcn, factor, diag)
minpack.error: Result from function call is not a proper array of floats.
我试图在没有运气的情况下捕获“TypeError”异常
如何让 python 继续运行代码?
编辑:
这是我的尝试,期待部分:
try:
popt, pcov = curve_fit(FTfuncSurface,x,log(y))
except TypeError:
popt = [0,0]