• FEATURED

View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

div/0 problem

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

#1Gaiiden  Staff Emeritus

Posted 06 July 2012 - 05:28 PM

A friend of mine is having trouble with some of her code - tried to help but not familiar with Python at all I'm afraid. She's pretty much teaching herself for her internship and just picked up the language this week. I'm thinking it's not possible to use a floating point value as a for loop iterator that is perhaps causing s to revert to 0.

She gets the div/0 error on line 13

[source lang="py"]#input array of data as the h(x) [DataIn]#use the FamilyWavelet equation with w, s changing through the loop--random #values#multiply h(x) and FamilyWavelet and sum them upimport numpy as npimport matplotlib.pyplot as pltdef MotherWavelet(eta, w): x = np.pi**(-1./4)*np.exp(1j*w*eta)*np.exp((-eta**2)/2.) return xdef FamilyWavelet(n,n1,w,s,dt): x = (dt/s)**(1./2.) N = ((n1-n)*(dt))/s mw = MotherWavelet(N, w) r = x*mw return r#will get data from fileDataIn = np.loadtxt('/Users/Devan/Documents/SLAC/Projects/wavlet_tutorial/data/nino3sst.dat')newArray = np.zeros((len(DataIn)))totalSumN1 = np.zeros((120)) #want 120 spots in the arraytotalSumS = np.zeros((200)) #100 spots in the arraya = 0n1 = 0w = 5s = 0.2b = 0#an array of all the n1s from 0 to 200for n1 in range(120): for s in range(4): for a in range(len(DataIn)): y = FamilyWavelet(a, n1, w, s, 0.4) c = DataIn[a] * y.conj() newArray[a] = c y = np.sum(newArray) totalSumS[b] = y b +=1 for a in range(len(DataIn)): y = FamilyWavelet(a, n1, w, s, 0.4) c = DataIn[a] * y.conj() newArray[a] = c y = np.sum(newArray) totalSumN1[b] = y b +=1print np.concatenate((totalSumS, totalSumN1))[/source]

Edited by Gaiiden, 06 July 2012 - 05:29 PM.

Drew Sikora
Executive Producer
GameDev.net

#2ApochPiQ  Moderators

Posted 06 July 2012 - 05:35 PM

There may be other bugs, but I suspect "for s in range(4)" should be "for s in range(1, 4)" - otherwise s will start at 0 and cause a div/0 immediately in FamilyWavelet.
Wielder of the Sacred Wands

#3Gaiiden  Staff Emeritus

Posted 06 July 2012 - 07:14 PM

yea, I also noticed she wanted s to carry in a predefined value for the initial loop and I'm not sure that's possible given the for loops seem to auto-increment. Unless something like range(0.2, 4) would work?

Drew Sikora
Executive Producer
GameDev.net

#4SiCrane  Moderators

Posted 06 July 2012 - 07:27 PM

I's not clear what you would want range(0.2, 4) to do. In any case, the range() function only accepts integer arguments, which can be annoying at times. It is possible to use a list comprehension in conjunction with a range() statement to generate floating point increments. Ex: [x * 0.1 for x in range(2, 40, 2)] would generate the numbers 0.2 to 3.8 with a 0.2 increment.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.