【问题标题】:Python - TypeError: 'float' object is not callable [duplicate]Python - TypeError:'float'对象不可调用[重复]
【发布时间】:2015-12-18 21:43:14
【问题描述】:

目前已经得到如下代码:

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

【问题讨论】:

    标签: python


    【解决方案1】:

    不要调用函数,传给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)
    

    【讨论】:

    • 完成但它给出了同样的错误。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2019-11-25
    相关资源
    最近更新 更多