Python-TypeError:';浮动';对象不可调用
目前已获得以下代码:Python-TypeError:';浮动';对象不可调用,python,Python,目前已获得以下代码: class beam(object): def __init__(self, E, I, L): self.E = E self.I = I self.L = L self.Loads = [(0.0, 0.0)] #[(Force, distance along beam)] def getTotalDeflection(self, x): """Cal
class beam(object):
def __init__(self, E, I, L):
self.E = E
self.I = I
self.L = L
self.Loads = [(0.0, 0.0)] #[(Force, distance along beam)]
def getTotalDeflection(self, x):
"""Calculate total deflection of beam due to multiple loads"""
loadsList = self.Loads
beam.beamDeflection(loadsList, x)
def getSlope(self, x):
"""Calculate gradient at a point x on beam due to deflection
"""
import scipy.misc
return scipy.misc.derivative(self.getTotalDeflection(x), x)
对于函数getSlope(),我需要通过求挠度对x的导数来计算斜率。但是,我得到以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\X\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\X\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/X/Downloads/beamModel.py", line 12, in <module>
class beam(object):
File "C:/Users/X/Downloads/beamModel.py", line 67, in beam
print b.getSlope(1.0)
File "C:/Users/X/Downloads/beamModel.py", line 62, in getSlope
return scipy.misc.derivative(self.getTotalDeflection(x), x)
File "C:\Users\X\Anaconda2\lib\site-packages\scipy\misc\common.py", line 258, in derivative
val += weights[k]*func(x0+(k-ho)*dx,*args)
TypeError: 'float' object is not callable
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“C:\Users\X\Anaconda2\lib\site packages\spyderlib\widgets\externalshell\sitecustomize.py”,第685行,在runfile中
execfile(文件名、命名空间)
文件“C:\Users\X\Anaconda2\lib\site packages\spyderlib\widgets\externalshell\sitecustomize.py”,第71行,在execfile中
exec(编译(脚本文本,文件名,'exec'),glob,loc)
文件“C:/Users/X/Downloads/beamModel.py”,第12行,在
类梁(对象):
文件“C:/Users/X/Downloads/beamModel.py”,第67行,在beam中
打印b.getSlope(1.0)
文件“C:/Users/X/Downloads/beamModel.py”,第62行,在getSlope中
返回scipy.misc.derivative(self.getTotalDeflection(x),x)
文件“C:\Users\X\Anaconda2\lib\site packages\scipy\misc\common.py”,第258行,派生形式
val+=权重[k]*func(x0+(k-ho)*dx,*args)
TypeError:“float”对象不可调用
不要调用该函数,将其传递到scipy.misc.derivative
,例如
def getSlope(self, x):
"""Calculate gradient at a point x on beam due to deflection
"""
import scipy.misc
return scipy.misc.derivative(self.getTotalDeflection, x)
完成,但它给出了相同的错误。谢谢