Original Post
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 [font=courier new,courier,monospace]s[/font] 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 up
import numpy as np
import matplotlib.pyplot as plt
def MotherWavelet(eta, w):
x = np.pi**(-1./4)*np.exp(1j*w*eta)*np.exp((-eta**2)/2.)
return x
def 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 file
DataIn = 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 array
totalSumS = np.zeros((200)) #100 spots in the array
a = 0
n1 = 0
w = 5
s = 0.2
b = 0
#an array of all the n1s from 0 to 200
for 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 = 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 = y
b +=1
print np.concatenate((totalSumS, totalSumN1))
[/source]
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 up
import numpy as np
import matplotlib.pyplot as plt
def MotherWavelet(eta, w):
x = np.pi**(-1./4)*np.exp(1j*w*eta)*np.exp((-eta**2)/2.)
return x
def 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 file
DataIn = 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 array
totalSumS = np.zeros((200)) #100 spots in the array
a = 0
n1 = 0
w = 5
s = 0.2
b = 0
#an array of all the n1s from 0 to 200
for 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 = 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 = y
b +=1
print np.concatenate((totalSumS, totalSumN1))
[/source]