05.04.18 19:52, Peter O'Connor пише:
I propose a new "Reduce-Map" comprehension that allows us to write:
signal = [math.sin(i*0.01) + random.normalvariate(0, 0.1)for iin range(1000)]
smooth_signal = [average = (1-decay)*average + decay*xfor xin signalfrom
average=0.]
Using currently supported
On Fri, Apr 06, 2018 at 11:02:30AM +1000, Chris Angelico wrote:
> On Fri, Apr 6, 2018 at 10:37 AM, Steven D'Aprano wrote:
[...]
> > All we need now is a way to feed in the initial value for average. And
> > that could be as trival as assigning a local name for it:
> >
> > average = 0
> >
> >
On Thu, Apr 05, 2018 at 12:52:17PM -0400, Peter O'Connor wrote:
> I propose a new "Reduce-Map" comprehension that allows us to write:
>
> signal = [math.sin(i*0.01) + random.normalvariate(0, 0.1) for i in
> range(1000)]
> smooth_signal = [average = (1-decay)*average + decay*x for x in signal
> f
On 04/05/2018 05:37 PM, Steven D'Aprano wrote:
On Thu, Apr 05, 2018 at 05:31:41PM -0700, Ethan Furman wrote:
[snip unkind words]
Be fair. Strip out the last "from average = 0" and we have little that
isn't either in Python or is currently being proposed elsewhere.
Ugh. Thanks for remindin
On Fri, Apr 6, 2018 at 10:37 AM, Steven D'Aprano wrote:
> On Thu, Apr 05, 2018 at 05:31:41PM -0700, Ethan Furman wrote:
>> On 04/05/2018 03:24 PM, Peter O'Connor wrote:
>>
>> >Well, whether you factor out the loop-function is a separate issue. Lets
>> >say we do:
>> >
>> > smooth_signal = [av
On Fri, Apr 06, 2018 at 10:29:19AM +1000, Steven D'Aprano wrote:
> - That you call it "MapReduce" while apparently doing something
> different from what other people call MapReduce:
Actually, no you don't -- you call it "Reduce-Map". Sorry, my mistake.
--
Steve
__
On Thu, Apr 05, 2018 at 05:31:41PM -0700, Ethan Furman wrote:
> On 04/05/2018 03:24 PM, Peter O'Connor wrote:
>
> >Well, whether you factor out the loop-function is a separate issue. Lets
> >say we do:
> >
> > smooth_signal = [average = compute_avg(average, x) for x in signal
> > from a
On Thu, Apr 05, 2018 at 06:24:25PM -0400, Peter O'Connor wrote:
> Well, whether you factor out the loop-function is a separate issue. Lets
> say we do:
>
> smooth_signal = [average = compute_avg(average, x) for x in signal from
> average=0]
>
> Is just as readable and maintainable as yo
On 04/05/2018 03:24 PM, Peter O'Connor wrote:
Well, whether you factor out the loop-function is a separate issue. Lets say
we do:
smooth_signal = [average = compute_avg(average, x) for x in signal from
average=0]
Is just as readable and maintainable as your expanded version, but saves
On Thu, Apr 5, 2018, 5:32 PM Peter O'Connor
wrote:
> I find this a bit awkward, and maintain that it would be nice to have this
> as a built-in language construct to do this natively. You have to admit:
>
> smooth_signal = [average = (1-decay)*average + decay*x for x in signal
> from average
Well, whether you factor out the loop-function is a separate issue. Lets
say we do:
smooth_signal = [average = compute_avg(average, x) for x in signal from
average=0]
Is just as readable and maintainable as your expanded version, but saves 4
lines of code. What's not to love?
On Thu, A
On 5 April 2018 at 22:26, Peter O'Connor wrote:
> I find this a bit awkward, and maintain that it would be nice to have this
> as a built-in language construct to do this natively. You have to admit:
>
> smooth_signal = [average = (1-decay)*average + decay*x for x in signal
> from average=0.]
Ah, that's nice, I didn't know that itertools.accumulate now has an
optional "func" parameter. Although to get the exact same behaviour
(output the same length as input) you'd actually have to do:
smooth_signal = itertools.islice(itertools.accumulate([initial_average]
+ signal, compute_avg), 1
> On 2018 Apr 5 , at 12:52 p, Peter O'Connor wrote:
>
> Dear all,
>
> In Python, I often find myself building lists where each element depends on
> the last. This generally means making a for-loop, create an initial list,
> and appending to it in the loop, or creating a generator-function.
On 04/05/2018 09:52 AM, Peter O'Connor wrote:
[snip html code snippets]
Please don't use html markup. The code was very difficult to read.
--
~Ethan~
___
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/py
On 05/04/18 17:52, Peter O'Connor wrote:
Dear all,
In Python, I often find myself building lists where each element depends on
the last. This generally means making a for-loop, create an initial list,
and appending to it in the loop, or creating a generator-function. Both of
these feel more ve
Dear all,
In Python, I often find myself building lists where each element depends on
the last. This generally means making a for-loop, create an initial list,
and appending to it in the loop, or creating a generator-function. Both of
these feel more verbose than necessary.
I was thinking it wo
17 matches
Mail list logo