<br><div><span class="gmail_quote">On 5/1/07, <b class="gmail_sendername">John Washakie</b> <<a href="mailto:washakie@gmail.com">washakie@gmail.com</a>> 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've<br>taken half the time in the morning, but here's what I've come up with<br>(any suggestions for improvements, or course are welcome):<br><br>
for d in data:<br> w = len(d)<br> if d[0] <= tinit+60:<br> d = column_stack(d)<br> cnt,sum = cnt+1,sum+d<br><br> else:<br> avg = sum/(ones(w)*cnt)<br> tinit,cnt,sum = d[0],0,zeros(n)
<br> if init==0:<br> newData,init = avg,1<br> else:<br> newData = append(newData,avg,axis=0)<br><br> 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>>>> numbers=[1,2,3,4,5]<br>>>> numbers.append(6)<br>>>> numbers<br>[1, 2, 3, 4, 5, 6]<br>>>> sum(numbers)<br>
21<br>>>> len(numbers)<br>6<br>>>> sum(numbers)/len(numbers) <br>
3<br><br>WAIT WAIT hold the phone!? 21/5 is NOT 3! It's 3.5! 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>>>> sum(numbers)*
1.0/len(numbers)<br>3.5<br><br>So there is our average. If floor division doesn't make sense to you, you aren't alone. This changes in Python 3000. 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'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>