[Python-talk] reduction Q
bruce.labitt at autoliv.com
bruce.labitt at autoliv.com
Thu Oct 22 11:01:42 EDT 2009
There is a generator function that produces as its output 2 arrays, a and
b. I'd like to get the average of the ith elements for both arrays. The
a and b arrays are the same length, if it matters.
(a,b) = ( myfunc( args ) for f in freqarray )
can I do something like the following?
(suma,sumb) = reduce(add, (a, b)) # this stops the generator chain...
(avga, avgb) = ( suma, sumb)/freqarray.size
example: freqarray has 2 elements, then
a[0,:] = [ 1, 2, 3, ..., 300] b[0,:] = [300, 299, 298,
..., 1]
a[1,:] = [ 0, 1, 2, ..., 299] b[1,:] = [299, 298, 297,
..., 0]
suma = [ 1, 3, 5, ..., 599] sumb = [ 599, 597, 595,
..., 1]
avga = [ 0.5, 1.5, 2.5, ..., 145.5] avgb = [ 599/2., 597/2., 595/2.,
..., 0.5]
I don't want arrays a and b to interact. Is there a way to do this? I
haven't tried this, but it seems like trouble is written all over it :P
Bruce
Bruce Labitt
Autoliv Electronics
1011B Pawtucket Blvd, PO Box 1858
Lowell, MA 01853
Email: bruce.labitt at autoliv.com.
Tel: (978) 674-6526
Fax: (978) 674-6581
******************************
Neither the footer nor anything else in this E-mail is intended to or constitutes an <br>electronic signature and/or legally binding agreement in the absence of an <br>express statement or Autoliv policy and/or procedure to the contrary.<br>This E-mail and any attachments hereto are Autoliv property and may contain legally <br>privileged, confidential and/or proprietary information.<br>The recipient of this E-mail is prohibited from distributing, copying, forwarding or in any way <br>disseminating any material contained within this E-mail without prior written <br>permission from the author. If you receive this E-mail in error, please <br>immediately notify the author and delete this E-mail. Autoliv disclaims all <br>responsibility and liability for the consequences of any person who fails to <br>abide by the terms herein. <br>
******************************
More information about the Python-talk
mailing list