Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40276 > unrolled thread

Putting the loop inside of loop properly

Started byIsaac Won <winefrog@gmail.com>
First post2013-03-01 10:07 -0800
Last post2013-03-01 18:40 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Putting the loop inside of loop properly Isaac Won <winefrog@gmail.com> - 2013-03-01 10:07 -0800
    Re: Putting the loop inside of loop properly MRAB <python@mrabarnett.plus.com> - 2013-03-01 18:40 +0000

#40276 — Putting the loop inside of loop properly

FromIsaac Won <winefrog@gmail.com>
Date2013-03-01 10:07 -0800
SubjectPutting the loop inside of loop properly
Message-ID<af67d0e3-63ea-4c94-8c84-afc144361654@googlegroups.com>
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

[toc] | [next] | [standalone]


#40279

FromMRAB <python@mrabarnett.plus.com>
Date2013-03-01 18:40 +0000
Message-ID<mailman.2744.1362163249.2939.python-list@python.org>
In reply to#40276
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']

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web