4,494
edits
(Created Windowed Reduce Page) |
No edit summary |
||
Line 3: | Line 3: | ||
== Description == | == Description == | ||
When applied to a [[vector]] argument, <source lang=apl inline>n f/x</source> evaluates to the expression <source lang= | When applied to a [[vector]] argument, <source lang=apl inline>n f/x</source> evaluates to the expression <source lang=apl inline>(a f b f c)(b f c f d)</source>… where <source lang=apl inline>a</source>, <source lang=apl inline>b</source>, <source lang=apl inline>c</source>, <source lang=apl inline>d</source>, … are the elements of <source lang=apl inline>x</source>, grouped into windows of size <source lang=apl inline>n</source>. It works like [[Reduce]], except applied on overlapping segments of an array, and borrows most of its functionality from it. When | ||
<source lang=apl inline>n</source>is negative, each window is reversed before the reduction is done. | |||
== Examples == | == Examples == | ||
Line 14: | Line 14: | ||
2-/1 2 3 4 5 | 2-/1 2 3 4 5 | ||
¯1 ¯1 ¯1 ¯1 | ¯1 ¯1 ¯1 ¯1 | ||
¯2-/1 2 3 4 5 | |||
1 1 1 1 | |||
4,/35 56 67 79 91 | 4,/35 56 67 79 91 | ||
┌───────────┬───────────┐ | ┌───────────┬───────────┐ | ||
Line 19: | Line 21: | ||
└───────────┴───────────┘ | └───────────┴───────────┘ | ||
</source> | </source> | ||
== Notable uses == | |||
Windowed Reduce is especially common with a left argument of 2 or ¯2, as it is then a pair-wise application of the operand between neighbouring elements, and especially so with [[comparison functions]]. For example, <source lang=apl inline>1,2≠/v</source> indicates the elements that differ from their neighbour on the left. For a Boolean vector <source lang=apl inline>b</source>, the expression <source lang=apl inline>2</0,b</source> indicates the first 1 in each contiguous run of 1s. | |||
== See also == | |||
* [[Stencil]] which can be seen as a generalisation of Windowed Reduce in that for a vector argument, <source lang=apl inline>({⊂f/⍵}⌺n)v</source> is equivalent to <source lang=apl inline>n f/ v</source> except in how they deal with the ends of the vector; Stencil includes "shards" and Windowed Reduce does not. | |||
== External links == | == External links == |