# Triple nested loop python (While loop insde of for loop inside of while loop)

Isaac Won winefrog at gmail.com
Fri Mar 1 09:59:59 CET 2013

```try to make my triple nested loop working. My code would be:
c = 4
y1 = []
m1 = []
std1 = []
while c <24:
c = c + 1
a = []
f.seek(0,0)
for columns in ( raw.strip().split() for raw in f ):
a.append(columns[c])
x = np.array(a, float)
not_nan = np.logical_not(np.isnan(x))
indices = np.arange(len(x))
interp = interp1d(indices[not_nan], x[not_nan], kind = 'nearest')
p = interp(indices)

N = len(p)
dt = 900.0 #Time step (seconds)
fs = 1./dt #Sampling frequency
KA,PSD = oned_Fourierspectrum(p,dt) # Call Song's 1D FS function
time_axis = np.linspace(0.0,N,num = N,endpoint = False)*15/(60*24)
plot_freq = 24*3600.*KA #Convert to cycles per day
plot_period = 1.0/plot_freq # convert to days/cycle
fpsd = plot_freq*PSD
d = -1
while d <335:
d = d + 1
y = fpsd[d]
y1 = y1 + [y]
m = np.mean(y1)
m1 = m1 + [m]
print m1
--------------------------------------------------------------------------------

My purpose is make a list of [mean(fpsd), mean(fpsd), mean(fpsd).. mean(fpsd)]. Each y1 would be the list of fpsd[d].

I check it is working pretty well before second while loop and I can get individual mean of fpsd[d]. However, with second whole loop, it produces definitely wrong numbers. Would you help me this problem?

```