TypeError: object 'type' has no attribute '__getitem__'

I am trying to run the rmakeprofile command. I am getting an error stating that the "type" object has no attribute 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

      

Here is the trace

    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__'

      

+3


source to share


1 answer


Try the following substitutions.

    import numpy as np
    self.a = np.asarray(['d'])

      



or even this also works

    import numpy as np
    self.a = np.asarray('d')

      

-1


source







All Articles