BTMpy icon indicating copy to clipboard operation
BTMpy copied to clipboard

float division by zero

Open ZoeM2016 opened this issue 7 years ago • 3 comments

hello,i don't konw why i run the code s = self.sum() assert(s>=0)

    K = len(self.p)
    for i in range(K):
        self.p[i] = (self.p[i] + smoother)/(s + K*smoother)

An error occurred: File "C:\Users\zoe_zoe\Desktop\BTMpy-master3\BTMpy-master\src\pvec.py", line 99, in normalize self.p[i] = (self.p[i] + smoother)/(s + K*smoother) ZeroDivisionError: float division by zero Could you please tell me how to modify the code?Thanks

ZoeM2016 avatar Dec 09 '18 02:12 ZoeM2016

I don't know which line is this code, and i just can't exactly solve it.

jasperyang avatar Dec 10 '18 03:12 jasperyang

sorry,i didn't put it very clearly.this code is in pvec.py line99

def normalize(self,smoother=0.0): s = self.sum() assert(s>=0) K = len(self.p) for i in range(K): self.p[i] = (self.p[i] + smoother)/(s + K*smoother)

when i run this, self.sum=0 and self.p=0

ZoeM2016 avatar Dec 10 '18 03:12 ZoeM2016

you can change code in indexDocs.py line 18 and line 28 to this :

print(' '.join(map(str, wids)), file=wf)

print('%d\t%s' % (wid, w), file=wf)

amingjiang avatar Nov 23 '19 07:11 amingjiang