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. 3 followers. Post Follow

1 Replies
492 Views

Similar Articles

[PageSpeed] 40

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:

Similar Artilces:

Triple nested loop python (While loop insde of for loop inside of while loop)
try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c <24: c = c + 1 a = [] f.seek(0,0) 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) dt = 900.0 #Time step (seconds) fs = 1./dt #Sampling frequency KA,PSD = oned_Fourierspectrum(p,dt) # Call Song's 1D FS function time_axis = np.linspace(0.0,N,num = N,endpoint = False)*15/(60*24) plot_freq = 24*3600.*KA #Convert to cycles per day plot_period = 1.0/plot_freq # convert to days/cycle fpsd = plot_freq*PSD d = -1 while d <335: d = d + 1 y = fpsd[d] y1 = y1 + [y] m = np.mean(y1) m1 = m1 + [m] print m1 -------------------------------------------------------------------------------- My purpose is make a list of [mean(fpsd[0]), mean(fpsd[1]), mean(fpsd[2]).. mean(fpsd[335])]. Each y1 would be the list of fpsd[d]. I check it is working pretty well before second while l...

while loop inside a for loop
Hi, can someone please tell me why "time" (t) is not updated correctly within the while loop? Please run this small code in your machine and you'll know what I'm taking about. What I want is: for t=1 run the "while loop" until iq<=(numberc-1) then t=2 run the "while loop" again until iq<=(numberc-1), and so on. Basically, this code runs through all the nonzero elements of A and attempts to divide them individually into two, once a certain time has passed. Please feel free to ask for clarifications. Many thanks in advance. A=[0 0 0 0 0 0 ...

loops in loops
In the attached vi, the one second loop runs at one second and can't be touched.&nbsp; In the ten second loop, the ten second clock is a stand in for a process that generates a finished signal. The problem is once the process is complete, to start it again, leave the one second loop running, and start an additional process that will take less time than 10 seconds. thanks internal loops.vi: http://forums.ni.com/attachments/ni/170/319512/1/internal loops.vi Hi exo, what do you try there? If you start your vi, the value from your stop button will be read and after that, both loops &quo...

while loop in a while loop
Hi All, I have the following situation: while(rs.next()) { //loop1 while(rs2.next()) { //loop 2 } } It seems like loop 2 is only beeing used once. Should I after loop2 put the cursor back to the beginning? if so, how do I do that? Thanks! -- Posted by news://news.nb.nu Steven wrote: > Hi All, > > I have the following situation: > > > while(rs.next()) { //loop1 > > while(rs2.next()) { > //loop 2 > } > > } > The architypal loop (for a List eg ArrayList of Blah objects) is: for(It...

while loop in a while loop
Hi all, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I am trying to write a program with a while loop within another while loop. When I run the vi both while loops&nbsp; run but then only the inner while loop seems to update, I adjust controls and they have no effect on the indicators. &nbsp; Thanks.. You need to familiarize with the concept of dataflow programming. Run your VI in "execution highligthing" mode while watching the diagram and you'll get a better feeling on how things work. :) &nbsp; If both loops need to run in para...

WHILE LOOP AS FOR LOOP
its possible? For each id in (SELECT * FROM table) INSERT INTO table2(id,fk,nombre) values(1,id,'xxx'); Jessica Gonz�lez (jess.rgm@gmail.com) writes: > its possible? > > For each id in (SELECT * FROM table) > INSERT INTO table2(id,fk,nombre) > values(1,id,'xxx'); > So in SQL, you don't normally code the loops explicitly - the loops are hidden on the inside. Logically, it is an operation of a set. INSERT table(id, fk, nombre) SELECT 1, id, 'xxx' FROM table -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx thanks.. but SET IDENTITY_INSERT table ON; INSERT INTO table(pk,activo,permiso,rol) SELECT IDENT_CURRENT('table')+1,'S',id, 1 FROM table2 return error Violation of PRIMARY KEY constraint 'PK__table__3213E83F2B947552'. Cannot insert duplicate key in object 'table'. The duplicate key value is (6). only 'id' i need get from table2 Jessica Gonz�lez (jess.rgm@gmail.com) writes: > thanks.. but > > SET IDENTITY_INSERT table ON; > INSERT INTO table(pk,activo,permiso,rol) > SELECT IDENT_CURRENT('table')+1,'S',id, 1 > ...

for loop into for loop.
Hello this is my first time that i am writing here.. I need your help to improve my code. This is my code for a=1:numberOfShortestPaths for b=a+1:a+numberOfShortestPaths for c=b+1:b+numberOfShortestPaths for d=c+1:c+numberOfShortestPaths for e=d+1:d+numberOfShortestPaths total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)+weight(:,:,e); maximum=max(total_weight); end end end end end i want to do this function "automatically" because the letters ...

For loop over a while loop
Hi, I am computing a quantity that depends on two variables. The computation itself is iterative (i'm using 3 while loops to compute it). Now i want to do a sensitivity analysis of the input variables and do a 3D plot where I can start making sense out of my results, however not sure how to write a for loop over these while loops to compute different combinations of what I define as my parametric space for my two input variables. Thanks in advance, Vash Please add a code example and/or more specific question.... ...

FOR loop not looping
I have the below script that uses 2 for loops. for some reason they loop is not looping ! /bin/ksh CURR_PATH='/main/nedcor/flexcube' cd $CURR_PATH for DIR1 in 'WIP' 'INPUT';do echo $DIR1 for DIR in $(find . -name $DIR1);do RESULT=`ls -A $DIR | egrep -v "BKUP|BKP"` echo $DIR echo $RESULT echo $RESULT1 if [ -z "$RESULT" ] ; then echo "No Files found" exit 0 else echo file $RESULT found exit 1 ...

LOOP and +LOOP
With LOOP, since the index (I) increases by 1 with each loop iteration, we can test for equality as a means to determine if it's time to exit the loop or not: : TEST 10 0 DO I . LOOP ; TEST 0 1 2 3 4 5 6 7 8 9 Here, when I gets to 10, the loop exits. It's not so easy with +LOOP, since the index can be changed by any arbitrary value on each iteration: : TEST 100 0 DO I . RANDOM +LOOP ; Here, we cannot test for equality. We have to test for crossing a boundary instead, at least as far as I can see. With that in mind, are these following results correct: : TEST 10 0 DO I . 1 +LOOP ...

timed loop inside a while loop
Hi all, I want to ask if I have a timed loop inside a&nbsp; while loop ,&nbsp; the timed loop&nbsp; does a certain task &nbsp;a 100 iteration ( each time loop iteration is 2 second duration)&nbsp;each while loop iteration &nbsp;, at each&nbsp; while loop iteration the time loop writes the actual time spent to a text file for this certain task. &nbsp; for the next while loop, the timed loop contiues&nbsp; to write the time spent from the previous while loop ( ex the first while loop the time loop ends the last results with 200 second for a 100&nbsp; time ...

Nested While loop inside For loop
I have been coding in matlab for a while and I am confused about the below code: It seems like the "For loop" iterator variable "Index" does not update inside the "While loop". Please help me understand! I hate to assume this is some error induced on Matlab's end. ---------- CODE ------------ for Index = 390000:length(Stopxy) fprintf('Index: %d, \n',Index); while (Stopxy_YCoord(Index) < LowToHighThresh) fprintf('Index: %d, Yval: %f \n',Index,Stopxy_YCoord(Index)); Stopxy_YCoord(Index); Index = Index + 1; ...

Ending a while loop inside a while loop
How do I make a while loop run as long as the while loop that contains it is running? I tried wiring both conditional terminals to a stop button in the outer loop, but that doesnt seem to work? Is there another way? &nbsp; Thanks. It doesn't work because of data dependency. Once you are inside the inner loop the outer loop will not go to the next iteration until the inner loop is done. It sounds to me like you want parallel loops running, rather than one inside the other. If you open the Example Finder (Help -&gt; Find Examples), and search for "loops", open the examples...

what diference between timed loop and while loop and for loop
If I want to count 2 second working in the loop and next then going out of the loop I don't know&nbsp;which the loop &nbsp;I can use Message Edited by Jairak on 07-26-2008 03:14 PM Why do you need a loop to count for 2 seconds? To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's <a href="http://zone.ni.com/devzone/cda/tut/p/id/5054" target="_blank">Learning Center</a> which provides links to other materials and other tutorials. You can also take the <a href=...

Nested FOR loops. (a loop within a loop)
I can't get my head around them. I have two MySQL tables, one contains the categories, the other contains the posts. Each post is linked to a category. Now I'm trying to display each post with a drop down menu that has the categories in it and have the category that the post is in selected. Here's my code for the drop down menu where my woes lie. for ($i=0; $i<count($posts); $i++) { for ($j=1; $j<=count($categories); $j++) { if ($j == $post[$i]['id']) { selected = ' selected="selected"'; } else { sele...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot;
I think I have a similar problem - I have a while loop with Flat Sequence controlled for loop that produces output. This output needs to be displayed every while loop pass, but I get no output as the while loop feeds back thru a shift register and repeats all the innner funcions without sending the ouput to form new entries in the array. &nbsp; Is there any way we could stop the while loop for a split second (but practically just for no time, so that no time is wasted when it outputs the data)? &nbsp; Or is it a bad approach altogether? &nbsp; Appreciate any advice. &nbsp; kolo...

Re: i am having a problem with while loops, i have two while loops, i have a random number generator inside the &quot;inside&quot; loop and i want to read an array outside the &quot;outer&quot; #2
Hi guys, Apologies about he messy thread - I needed asolution urgently and I didn't get a chance to notice the post date. &nbsp; :Ravens - Thank you a lot. The solution, also found in "my assignmnet live update.vi", works perfectly, doing exactly what I needed. Thanks again. kolorek ...

speed up for loop inside for loop short question
Hi there, Given three column vectors x,y,z I want to calculate the probabilities: P(X<Y<Z), P(X=Y<Z), P(X<Y=Z), P(X=Y=Z). The following code gets the job done but I would like it to be faster. Is there a way of getting rid of at least one of the for loops? (I described the problem above instead of just giving the code because it might be helpful for someone to take a completely different approach, or check me (I think this is correct). Anyway if you are bored to check, any ideas regarding the speed would be more than welcome!). Thanx in advance for any answers! o...

conditional loops (while loops)
I am using a while loop to check a digital input. I would like to send the value to a true or false box to check another digital input. The problem is that the while loop is running continuously but not giving anything out through the connection. I am looking for something like "if this do that conditional". Is there a way to set this up? Hello! The =93if this, do that conditional=94 tools in LabVIEW are the Select function (All Functions >> Comparison subpalette) and the Case Structure (All Functions >> Structures subpalette), depending on the complexity of what you wa...

Radio Button Loop inside Form Element Loop
I have a for loop seen below.... var the_form = document.getElementById(formName); for(var i=0; i<the_form.length; i++) { var temp = the_form.elements[i].type; if (temp == "radio") { for (x = 0; x < the_form.elements[i].length - 1; x++) { //do stuff } } } Right before the inside loop I do the following and next to its the results, any idea why the last one returns 0? alert(the_form.elements[i].id); // returns question1 alert(the_form.question1.length); // returns 4 (amount of radio buttons in that group) alert(the_form.elements[i].length); // returns 0 I...

Loop within a loop ???
Hi, I'm having trouble copying table data to new records. I have two tables as follows: *** Specifications (Table) specification_ID (field) LINKED product_ID (field) specification_header (field) ________________________________________ *** Specification_detail (Table) specification_detail_ID (field) specification_detail_text (field) specification_ID (field) LINKED specification_ID in this table is linked to specification_ID in Specifications. ________________________________________ On a form, related by product_ID, 'Specifications' fills a subform, no problem. When you cli...

nested loops only loop once
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another way I could write this to get both loops to complete fully? I am using the two while loops to pull data from different tables, and insert that data into a list that has html code surrounding each loop. while ($url = mysql_fetch_array($urls, MYSQL_ASSOC)) { $pn = $url['post_name']; while ($date = mysql_fetch_array($lmdate, MYSQL_ASSOC)) { $lm = $date['post_modified']; ...

Loop within Loop?
Is it allowed to have one do loop completely within another do loop in Fortran? On 3/27/2011 8:34 PM, Anne Onime wrote: > Is it allowed to have one do loop completely within another > do loop in Fortran? Of course...know of no programming language that prohibits such a construct. Why the question re: Fortran? -- dpb <none@non.net> wrote: > On 3/27/2011 8:34 PM, Anne Onime wrote: > > Is it allowed to have one do loop completely within another > > do loop in Fortran? > > Of course...know of no programming language that prohibits su...

Loop-Loop Calculation
Hi &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i have one VI in that i want to do Loop to Loop calculation. In my VI first the inner loop have to execute first . Loop-Loop calc.vi: http://forums.ni.com/attachments/ni/170/302256/1/Loop-Loop calc.vi I think you should explain better what you wean by "loop to loop calculation". What are you trying to accomplish? ...

Web resources about - Putting the loop inside of loop properly - comp.lang.python

Statement of Disaffiliation from the GUU regarding failure to properly address Misogynistic behaviour ...
Glasgow Uni Coalition of Resistance hat eine Notiz mit dem Titel Statement of Disaffiliation from the GUU regarding failure to properly address ...


How to use a Ketchup Cup Properly - YouTube
Ever carry over 8 cups full of ketchup back to your table, try to dunk more than one fry at a time, and think to yourself, "This doesn't seem ...

University reforms haven't been explained properly, says Sydney Uni's Michael Spence
... of the proposal to uncap university fees has taken an apparent swipe at the government's sales job saying the case for change hasn't been properly ...

Canada crash train brakes not set properly
A lone engineer failed to set brakes properly on a train that derailed and exploded in a small Canadian town, killing at least 15 people, the ...

Union says Dick Smith staff were 'not properly consulted' about concession closures
The union representing Dick Smith workers says staff at the electronic retailers' concession stores were &quot;not properly consulted&quot; about ...

Bill Shorten should resign after failing to properly disclose donations, says former ALP national secretary ...
A former national secretary of the Australian Labor Party, Bob Hogg, has called for Opposition Leader Bill Shorten to resign, accusing him of ...

Six items you're not cleaning properly and how to clean them
From mould in your coffee machine to fungus growing in your dishwasher, it’s safe to say you’ve missed a spot.

Fracking's effect on water not properly monitored, report finds
A new report commissioned by Environment Canada says there's little information about the effects of shale gas development on the environment. ...

'We want to know how to love them properly,' veteran's spouse says
A day after confronting the Veterans Affairs minister over lack of support for veterans’ caregivers, the wife of a former Canadian Forces sergeant ...

Resources last updated: 3/10/2016 4:06:33 PM