« first day (2522 days earlier)      last day (127 days later) » 

12:42 PM
@mappo You might like tacit.help.
 
1:00 PM
Welcome to APL Quest 2022-9! Today's quest is An Average Window (or a Windowed Average):
> Write a function that:
> • takes a right argument Y that is a numeric scalar or non-empty vector.
> • takes a left argument X that represents the number of neighboring elements on either side of each element in Y.
> • returns a numeric vector or scalar where each element is the average (mean) of the corresponding element in Y and its X neighbors on either side. If an element has fewer than X neighbors on either side, replicate the first and last values as necessary to make X neighbors.
 
(1+2×⊣)(+/÷⊣)⍴∘⊃,⊢,⍴∘(⊃⌽)
 
Very nice.
That, and its explicit equivalent is what I had too.
Two observations here: Would have been nice with monadic being Last.
It would have been nice if we could specify to that it should extend using the edge values.
 
@rabbitgrowth nice, had the same but not tacit. Was still working on that
 
@rabbitgrowth Btw, you can factor out the using Never mind.
 
@Adám How would that work? With ?
 
1:09 PM
No, stencil I Think
 
There's plenty of design space, e.g. in the left argument (not used at all currently) or by adding rows to the right operand.
 
@Adám Nice job after ⌸ you already worked on :)
 
Loved the presentation by the way!
@Richard I meant how would you specify that to
 
Thanks. This idea for actually preceeds the idea for
 
I tried to use for this problem but couldn't make it work nicely
 
1:13 PM
doesn't Extended do something with stencil edges?
 
It's filled with zero's if I remind correctly
 
@RubenVerg It does.
@Richard Right, although the operand gets info about how much was padded, so it could exchange those.
 
{x←1+2×⍺ ⋄ (+⌿÷≢)¨(-x)↓x↓{⊂⍵}⌺x⊢(x⍴⊃⍵),⍵,(x⍴⊃⌽⍵)} seems to work with stencil
 
But has a different problem too. It doesn't deal nicely with arguments that are so small that they need padding on both sides.
… which is exactly what @Silas addresses by padding first, then dropping extra results.
This is my idea for extending :
0 0│1 2 3 4 5│0 0  Zero
1 1│1 2 3 4 5│5 5  Replicate
2 1│1 2 3 4 5│5 4  Reverse
3 2│1 2 3 4 5│4 3  Mirror
4 5│1 2 3 4 5│1 2  Wrap
So you'd add a left argument or maybe a row to the right operand, with one edge spec per dimention, 0–4 for Zero (current behaviour), Replicate (what we'd need here), etc.
 
nice
 
1:21 PM
To avoid having to pad, Stencil could either omit padding info when impossible, or it could switch to giveone mask per dimension (but that would need to be extended to handle one mask per dimension too) or let it return a nested argument (extending and to do multiple take/drop operations at once).
Let me see if I can do the fill-with-edge-value, without padding first (though it won't work on small args).
 
@Adám how about no padding (call operand with smaller arrays)?
 
@RubenVerg No need, as they can just do
 
ah right
 
Here we go:
      {0>⍺:⊂(⍺↓⍵),(|⍺)⍴⊃⌽⍺↓⍵ ⋄ ⊂(⍺⍴⊃⍺↓⍵),⍺↓⍵}⌺5⊢1 2 3 4 5 6
┌─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│1 1 1 2 3│1 1 2 3 4│1 2 3 4 5│2 3 4 5 6│3 4 5 6 6│4 5 6 6 6│
└─────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
Of course plenty of optimisations possible, but you get the idea.
 
@Adám Any particular feelings either way?
 
1:32 PM
You mean extending / or switching to and extending ?
I would like to extend both, but I think I prefer keeping its behaviour. Having the actual amount of padding is often useful, as we just saw. It'd be more complicated to compute the leading and trailing 1s.
 
no, was wondering if you'd played with both extending stencil's ⍵⍵ and ⍺ and which you'd prefered. Seems from Extended prefer adding an ⍺ ?
 
@Adám here's an At-based one
{(⍵[⎕io⌈-⍺-⎕io])@(⍸(-≢⍵)↑1⍴⍨0⌈-⍺)⊢(⍵[⎕io⌈⍺+⎕io])@(⍸(≢⍵)↑1⍴⍨0⌈⍺)⊢⍵}
nevermind
it messes up the right edges
 
@Silas I think I prefer extending the right operand, as it anyway needs a column per dimension. I was using the left argument to indicate switching to a -based left argument, but then I came up with the extension to and .
 
can't tell why though, probably just that the index is wrong
 
Anyway bordering on unreadable.
 
1:37 PM
yeah, it seemed easier in my head :)
 
I recommend localising ⎕IO (or assuming 1) rather than trying to write agnostic code.
Well, I think we're all done then.
Next week is 2022-10: Separation Anxiety which is our 100th APL Quest!
 
Does NARS2000's § only work as an operand to , or does a standalone function for symmetric difference also exist? I can't find documentation for the latter and currently have no access to a Windows machine to try it out myself
 
Let me try. Works stand-alone too.
 
thanks
 

« first day (2522 days earlier)      last day (127 days later) »