f



Putting the loop inside of loop properly

I just would like to make my previous question simpler and I bit adjusted m=
y 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 =3D np.array(a, float)
        not_nan =3D np.logical_not(np.isnan(x))
        indices =3D np.arange(len(x))
        interp =3D interp1d(indices[not_nan], x[not_nan], kind =3D 'nearest=
')
        p =3D interp(indices)


        N =3D len(p)


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

                y =3D fpsd[d]
                y1 =3D y1 + [y]
                m =3D np.mean(y1)
        m1 =3D m1 + [m]
------------------------------------------------------------------
I just removed seemingly unnecesary lines. I expect that last loop can prod=
uce the each order values (first, second,.... last(336th)) of fpsd from for=
mer loop.
fpsd would be 20 lists. So, fpsd[0] in third loop shoul be first values fro=
m 20 lists and it expects to be accumulated to y1. So, y1 should be the lis=
t of first values from 20 fpsd lists. and m is mean of y1. I expect to repe=
at 356 times and accumulated to m1. However, it doesn't work and fpsd value=
s in and out of the last loop are totally different.
My question is clear?
Any help or questions would be really appreciated.
Isaac
0
winefrog (28)
3/1/2013 6:07:26 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

1 Replies
3568 Views

Similar Articles

[PageSpeed] 37

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']

0
python3897 (1417)
3/1/2013 6:40:49 PM
Reply: