<br><div><span class="gmail_quote">On 5/1/07, <b class="gmail_sendername">John Washakie</b> &lt;<a href="mailto:washakie@gmail.com">washakie@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It aint pretty! And if I had just walked away, it probably would&#39;ve<br>taken half the time in the morning, but here&#39;s what I&#39;ve come up with<br>(any suggestions for improvements, or course are welcome):<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;for d in data:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w = len(d)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if d[0] &lt;= tinit+60:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d = column_stack(d)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cnt,sum = cnt+1,sum+d<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;avg = sum/(ones(w)*cnt)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tinit,cnt,sum = d[0],0,zeros(n)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if init==0:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newData,init = avg,1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;newData = append(newData,avg,axis=0)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;return newData<br></blockquote></div><br><br><br>Sorry my last reply was so terse - I needed to catch a train. :)
<br><br>So you need to check out a couple of functions - namely sum.<br><br>&gt;&gt;&gt; numbers=[1,2,3,4,5]<br>&gt;&gt;&gt; numbers.append(6)<br>&gt;&gt;&gt; numbers<br>[1, 2, 3, 4, 5, 6]<br>&gt;&gt;&gt; sum(numbers)<br>
21<br>&gt;&gt;&gt; len(numbers)<br>6<br>&gt;&gt;&gt; sum(numbers)/len(numbers)&nbsp;&nbsp;&nbsp; <br>
3<br><br>WAIT WAIT hold the phone!?&nbsp; 21/5 is NOT 3!&nbsp; It&#39;s 3.5!&nbsp; The short story here is that you have to make on of the numbers a floating point to get the result to return a float, so do this:<br><br>&gt;&gt;&gt; sum(numbers)*
1.0/len(numbers)<br>3.5<br><br>So there is our average.&nbsp; If floor division doesn&#39;t make sense to you, you aren&#39;t alone.&nbsp; This changes in Python 3000.&nbsp; You can read about floor division here:<br><a href="http://www.python.org/doc/2.2.3/whatsnew/node7.html">
http://www.python.org/doc/2.2.3/whatsnew/node7.html</a><br><br>I don&#39;t quite know what your stack is for - it can probably be accomplished using some slices or other fun stuff.<br><br>Good luck, and welcome to python!
<br><br>