Class problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Class problem (/thread-24357.html) |
Class problem - duckduck23 - Feb-10-2020 Does anyone help me fix bugs here? It works well when I type a.seqtosymbols() first and then a.periods(). But what I want to do is to call a.periods() separately without the seqtosymbols() first. Many thanks, My link: https://bpaste.net/raw/OUNQ import numpy from numpy import array, exp, pi, arange, float64 class ipdft(object): def __init__(self, seq, dints,period = None): self.seq = seq self.length = len(seq) self.dints = dints def seqtosymbols(self): self.result = numpy.zeros(self.length, numpy.uint8) #create arrays array([1, 0], dtype=uint8) for i in range(0,self.length-1): if self.seq[i:i+2] in self.dints: self.result[i] = 1 return self.result def ipdft_inner(self, X, W, ulim, N): for p in range(ulim): w = 1 for n in range(N): if n != 0: w *= W[p] X[p] = X[p] + self.result[n] * w return X def period(self, llim = None, ulim = None): self.llim = 2 self.ulim = self.length - 1 self.periods = array(range(self.llim, self.ulim + 1)) self.W = exp(-1j*2*pi/arange(1, self.ulim + 1)) self.X = array([0 + 0j]*self.length) self.X = self.ipdft_inner(self.X, self.W, self.ulim, self.length) power = abs(self.X[self.llim-1:self.ulim]) #if self.period is not None: #return power[self.period-2] #return array(power), self.period return self.periods a = ipdft("ATGTATTGCTAAAAATAGCAATAAATAGCATAATTAAGCTTATTTATTTT","GC") RE: Class problem - Larz60+ - Feb-10-2020 you don't have a method named a.periods() how about a.period() RE: Class problem - jefsummers - Feb-10-2020 If you call a.period() first, it calls a.ipdft_inner() in line 31. If you have not defined a.result, then you will get an attribute error in line 22. |