【发布时间】: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