Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Putting the loop inside of loop properly

Reply
Thread Tools

Putting the loop inside of loop properly

 
 
Isaac Won
Guest
Posts: n/a
 
      03-01-2013
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
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      03-01-2013
On 2013-03-01 18:07, Isaac Won wrote:
> 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']

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
Difference between putting code in constructor and putting code in static{} Saurabh Java 6 05-30-2004 02:44 PM
Putting a server side control inside an html element attribute John Lau ASP .Net 4 05-05-2004 12:42 AM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM



Advertisments