Putting the loop inside of loop properly

I

Isaac Won

I just would like to make my previous question simpler and I bit adjusted my code with help with Ulich and Chris.
The basic structure of my code is:

for c in range(5,25):

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)


fpsd = plot_freq*PSD
f.seek(0,0)
for d in range(336):

y = fpsd[d]
y1 = y1 + [y]
m = np.mean(y1)
m1 = m1 + [m]
------------------------------------------------------------------
I just removed seemingly unnecesary lines. I expect that last loop can produce the each order values (first, second,.... last(336th)) of fpsd from former loop.
fpsd would be 20 lists. So, fpsd[0] in third loop shoul be first values from 20 lists and it expects to be accumulated to y1. So, y1 should be the list of first values from 20 fpsd lists. and m is mean of y1. I expect to repeat 356 times and accumulated to m1. However, it doesn't work and fpsd values in and out of the last loop are totally different.
My question is clear?
Any help or questions would be really appreciated.
Isaac
 
M

MRAB

I just would like to make my previous question simpler and I bit adjusted my code with help with Ulich and Chris.
The basic structure of my code is:

for c in range(5,25):

for columns in ( raw.strip().split() for raw in f ):
[snip]

When you're using .split() with no argument (split on any whitespace),
you don't need to use .strip() with no argument (strip any whitespace):
' foo bar '.strip().split() ['foo', 'bar']
' foo bar '.split()
['foo', 'bar']
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top