Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'initialize': 0.05; '"c"': 0.07; 'list?': 0.07; 'nested': 0.07; 'reason,': 0.07; 'be:': 0.09; 'doing?': 0.09; 'loop.': 0.09; 'pep': 0.09; 'posting.': 0.09; 'subject:while': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; 'suggest': 0.11; '24,': 0.16; 'concur': 0.16; 'eckhardt': 0.16; 'iteration': 0.16; 'subject: \n ': 0.16; 'tabs': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'working.': 0.17; 'code.': 0.20; 'changes': 0.20; 'modifying': 0.22; 'cc:2**0': 0.23; "python's": 0.23; 'seems': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'values': 0.26; 'am,': 0.27; 'question': 0.27; 'mix': 0.27; 'message-id:@mail.gmail.com': 0.27; 'initial': 0.28; 'run': 0.28; 'loop,': 0.29; 'url:mailman': 0.29; 'case,': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'fri,': 0.30; 'code': 0.31; 'problem.': 0.32; 'url:python': 0.32; 'url:listinfo': 0.32; 'problem': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'clear': 0.35; 'moved': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'add': 0.36; 'really': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'others.': 0.36; 'should': 0.36; 'subject: (': 0.36; 'bad': 0.37; 'drop': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'nothing': 0.38; 'sure': 0.38; 'step': 0.39; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'frequency': 0.65; 'greetings': 0.69; "(don't": 0.84; '2013': 0.84; '7:00': 0.84; 'different.': 0.84; 'isaac': 0.84; 'pass:': 0.84; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=ey4Yk3io6LviU7PQq72Me0lzR3n+I3aJS8k+JcnhtS4=; b=jjrfREOcLrfEWPbRfeqyASA1zRCfKCDlr/2CJslhh2Coo9wXHTn3YPQr0JKmB7F16F pbYXEuBg/NW1kCfB2EwInpW4YRMQdrWRTpXDLX/WGtN5f1TVObnmjAorqWMdvzah9lm3 06wTaezlqrjw9S0Fr6VwaPDBsFCpj+SIS8YRA6V2mJgV0qUlerZkblLpYUIevOIFEMPx IdsK1Q5X5szUsYzVqG6JAF5hk0r/QSBejYtY6sY3mbtHRuyQItg0pVKTo7zcwRdu5RVc 8WtWvUophC6om5NzFxvvRqEDVU5wb2oNEKSmccGPJQDp+jdekUHR4nKaUGjj10Acy54A CyMw== MIME-Version: 1.0 X-Received: by 10.220.119.147 with SMTP id z19mr3928863vcq.69.1362142801714; Fri, 01 Mar 2013 05:00:01 -0800 (PST) In-Reply-To: References: <118003ed-33f6-4d99-ac5e-99ec81921f45@googlegroups.com> Date: Fri, 1 Mar 2013 08:00:01 -0500 Subject: Re: Triple nested loop python (While loop insde of for loop inside of while loop) From: Joel Goldstick To: Ulrich Eckhardt Content-Type: multipart/alternative; boundary=bcaec54d4cfcd4687c04d6dc95c2 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 170 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362142804 news.xs4all.nl 6938 [2001:888:2000:d::a6]:41899 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40249 --bcaec54d4cfcd4687c04d6dc95c2 Content-Type: text/plain; charset=UTF-8 On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt < ulrich.eckhardt@dominolaser.com> wrote: > Am 01.03.2013 09:59, schrieb Isaac Won: > > try to make my triple nested loop working. My code would be: >> c = 4 >> > [...] > > while c <24: >> c = c + 1 >> > > This is bad style and you shouldn't do that in python. The question that > comes up for me is whether something else is modifying "c" in that loop, > but I think the answer is "no". For that reason, use Python's way: > > for c in range(5, 25): > ... > > That way it is also clear that the first value in the loop is 5, while the > initial "c = 4" seems to suggest something different. Also, the last value > is 24, not 23. > > > > I concur with Uli, and add the following thoughts: What is going on with [y]? Is this really a list? So what is y1 + y1 + [y] doing? > > while d <335: >> d = d + 1 >> y = fpsd[d] >> y1 = y1 + [y] >> m = np.mean(y1) >> m1 = m1 + [m] >> > > In your outer loop you initialize these values each pass: dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency This should me moved out of the loop since nothing changes with dt or fs > Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) and > the that "d in range(336)" is better style, you don't start with an empty > "y1", except on the first iteration of the outer loop. > > I'm not really sure if that answers your problem. In any case, please drop > everything not necessary to demostrate the problem before posting. This > makes it easier to see what is going wrong both for you and others. Also > make sure that others can actually run the code. > > > Greetings from Hamburg! > > Uli > > > > -- > http://mail.python.org/**mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com --bcaec54d4cfcd4687c04d6dc95c2 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt &= lt;ulr= ich.eckhardt@dominolaser.com> wrote:
Am 01.03.2013 09:59, schr= ieb Isaac Won:

try to make my triple nested loop working. My code would be:
c =3D 4
[...]

while c <24:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0c =3D c + 1

This is bad style and you shouldn't do that in python. The question tha= t comes up for me is whether something else is modifying "c" in t= hat loop, but I think the answer is "no". For that reason, use Py= thon's way:

=C2=A0 for c in range(5, 25):
=C2=A0 =C2=A0 =C2=A0 ...

That way it is also clear that the first value in the loop is 5, while the = initial "c =3D 4" seems to suggest something different. Also, the= last value is 24, not 23.



I concur with Uli, and add the following though= ts:=C2=A0 What is going on with [y]?=C2=A0 Is this really a list?=C2=A0 So = what is y1 + y1 + [y] doing?

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while d <335:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0d =3D d + 1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0y =3D fpsd[d]=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0y1 =3D y1 + [= y]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 m =3D np.mean(y1) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0m1 =3D m1 + [m]

In your outer loop you initialize these values = each pass:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 dt =3D 900.0 #Time step (seco= nds)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 fs =3D 1./dt #Sampling frequency

This should me moved out of the loop since nothing changes w= ith dt or fs

=C2=A0
Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) = and the that "d in range(336)" is better style, you don't sta= rt with an empty "y1", except on the first iteration of the outer= loop.

I'm not really sure if that answers your problem. In any case, please d= rop everything not necessary to demostrate the problem before posting. This= makes it easier to see what is going wrong both for you and others. Also m= ake sure that others can actually run the code.


Greetings from Hamburg!

Uli



--
http://mail.python.org/mailman/listinfo/python-list



--
--bcaec54d4cfcd4687c04d6dc95c2--