我在尝试运行rmakeprofile命令时遇到错误。我收到一条错误消息,指出'type'对象没有属性' getitem '
from array import array
from ROOT import gROOT, TCanvas, TProfile, TGraph
class Data(object):
def __init__(self, s):
self.p = TProfile()
self.data = []
for line in s:
if not line.startswith("#"): #Removes Commented lines
columns = line.split(',') #Splits into Columns
if columns:
datum = {
"threshold" : float(columns[1]),
"count" : float(columns[2]),
"rate" : float(columns[2]) /float(columns[0]),
"scantime" : float(columns[0])
}
self.data.append(datum)
print columns[1], float(columns[2])/float(columns[0])
def rmakeprofile(self, data, xval, yval, noBins):
self.a = array('d')
for datum in data:
self.a.append(float(datum[xval]))
self.p = TProfile('p','',noBins,min(self.a),max(self.a))
for datum in data:
self.p.Fill(datum[xval],datum[yval])
return self.p
这是追溯
p = d.rmakeprofile(data,"threshold","rate",13)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ray.py", line 27, in rmakeprofile
self.a = array('d')
TypeError: 'type' object has no attribute '__getitem__'
答案 0 :(得分:-1)
尝试使用以下替代品。
import numpy as np
self.a = np.asarray(['d'])
甚至这也有效
import numpy as np
self.a = np.asarray('d')