【问题标题】:TypeError: 'float' object is not callable issueTypeError:'float' 对象不是可调用的问题
【发布时间】:2019-11-23 10:34:18
【问题描述】:

我正在使用 PyROOT(ROOT 的扩展模块)尝试从另一个直方图创建一个直方图,用于粒子物理数据分析课程。当我尝试在一行中除以和乘以大量值时,我一直收到“'float' object is not callable'”错误。

from ROOT import TFile, TDirectory, TTree, TH1F, TCanvas
import math
import numpy as np

myfile = TFile("/home/hilary/root/compile/Research/angle_smearing.root")
hist = file.Get("Zenith_Angles")
hgm = TH1F('Fvsx', 'Smearing_Test_1',100,0,90)

for i in range(1, 100,1):
    for y in range (1, 100, 1):
        u = hist.GetBinCenter(i)
        N = hist.GetBinContent(i)
        o = 1
        x = hist.GetBinCenter(y)
        F = (N/(o*math.sqrt(2*math.pi))*math.e((-(x-u)**2)/(2*(o**2)))) 
        hgm.Fill(F)

c1 = TCanvas()
hgm.Draw()
c1.SaveAs("/home/hilary/Desktop/Out_going_muons_etc/smearing_test_1.png")

错误发生在读取的行

F = (N/(o*math.sqrt(2*math.pi))*math.e((-(x-u)**2)/(2*(o**2))))

错误是“TypeError: 'float' object is not callable”

【问题讨论】:

  • 这似乎是一个简单的错字;函数是math.exp
  • 你明白这个问题吗?该行中的某个变量是float,但它被用作函数,例如foo(...)。该行中只有两个类似函数的表达式,math.sqrt(...)math.e(...)() 的所有其他用途只是对数学运算进行分组。

标签: python python-3.x typeerror


【解决方案1】:

math.e 是一个常量float 值;您的意思是不是 math.exp,一个返回 e 的函数,提升到所提供参数的幂?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2015-10-26
    相关资源
    最近更新 更多