0

我正在使用 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]
4

1 回答 1

0

使用 try/except 块来捕获TypeError异常。

演示它的示例代码:

try:
   a = (1,2,3) #Some code
except IndexError:
   pass
于 2012-12-11T08:37:25.130 回答