[Python-talk] reduction Q
Lloyd Kvam
lkvam at venix.com
Thu Oct 22 15:23:12 EDT 2009
Sorry about totally misunderstanding your original post.
On Thu, 2009-10-22 at 14:11 -0400, bruce.labitt at autoliv.com wrote:
>
> def compute_response( f, h ):
> # a few calculations go here...
> retval = [ Ph, Pv, Prec ]
> return retval
>
> for hr in hrlist:
> arrays = (compute_response( freq, hr ) for freq in freqarray )
> (sumh, sumv, sumP) = reduce( add, arrays )
> dBh = 10.0*log10( sumh/ freqarray.size )
> dBv = 10.0*log10( sumv/freqarray.size )
> PdB = 10.0*log10( sumP/freqarray.size )
> # more stuff...
>
> The key was returning retval, rather than [Ph, Pv, Prec]. In this
> type of generator expression, one cannot return the tuple directly.
Well retval is a list (square brackets). There should be no difference
between returning the list and the name you've bound to the list.
If arrays is a sequence of lists, then reduce(add, arrays) should simply
flatten arrays into a single list. Is that add the operator.add?
Obviously, I still do not have a clue.
(And I won't make it to the meeting, so you want have a chance to make
me more cluefull...)
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 320-210-3409
More information about the Python-talk
mailing list