python - 任何人都可以帮助解决 TypeError : 'float' object is not callable' in following code

标签 python

我在下面的代码中编写了一个速度和加速度函数:

from math import exp

def kinematics(x,t,dt=1E-4):

    x=x(t)
    v_x=(x(t+dt)-x(t-dt))/(2*dt)
    a_x=(x(t+dt)-2*x(t)+x(t-dt))/(dt**2)
    return x,v_x,a_x

x=lambda t:exp(-(t-4)**2)

print(kinematics(x,5,dt=1E-5))

但是我得到以下错误:

TypeError: 'float' object is not callable

谁能指出错误?

最佳答案

您正在将 lambda 重新分配给 lambda 的返回值。

x=x(t)

在这一点之后,x 不再是 lambda,而是一个 float

关于python - 任何人都可以帮助解决 TypeError : 'float' object is not callable' in following code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55964278/

相关文章:

python - 无法解码 base64 编码的图像

python - 需要帮助清理 PyQt 和 python

python - 使用间隔索引在 DataFrame 中设置特定值

python - python 2.7 中的继承

python - SQLAlchemy:插入的刷新顺序错误?

python - 在 Python 中声明单字节变量

python - cpdef 和封装在 def 中的 cdef 有什么区别?

python - 未知层 : KerasLayer when i try to load_model

python - 高效计算二重积分

python http网络服务器