ArrayFilter[f,array,r]
applies f to all range-r blocks in the specified array.
ArrayFilter[f,array,{r1,r2,…}]
applies f to blocks with ranges r1, r2, … in successive dimensions.
ArrayFilter[f,array,template]
applies f over blocks specified by the position of 1s in the array template.
ArrayFilter
ArrayFilter[f,array,r]
applies f to all range-r blocks in the specified array.
ArrayFilter[f,array,{r1,r2,…}]
applies f to blocks with ranges r1, r2, … in successive dimensions.
ArrayFilter[f,array,template]
applies f over blocks specified by the position of 1s in the array template.
Details and Options
- ArrayFilter[f,array,…] requires that array is full array to a certain depth.
- ArrayFilter[f,array,r] applies f to all overlapping
blocks of elements in array. - Both array and template can be SparseArray objects.
- With ArrayFilter[f,array,template], neighborhood elements corresponding to 0s of template are replaced with Missing[] before being passed to f.
- ArrayFilter has the option Padding, which specifies how neighborhoods should be formed at the edges of the array. The following settings can be used:
-
None returns a smaller array val use val for padding "Fixed" repeat edge elements (default) "Periodic" periodic in each dimension
Examples
open all close allBasic Examples (3)
Apply f to each element of a list and its range-1 neighbors:
ArrayFilter[f, Range[10], 1]Apply f to each element of a list and its range-2 neighbors:
ArrayFilter[f, Range[10], 2]Apply f to all 3x3 blocks of range-1 neighbors around each element:
ArrayFilter[f, (| | | |
| --- | --- | --- |
| 1 | 2 | 3 |
| 10 | 20 | 30 |
| 100 | 200 | 300 |), {0, 1}]TraditionalForm[%]Scope (4)
Specify length-3 blocks using a template:
ArrayFilter[fun, {a, b, c, d, e, f}, {1, 1, 1}]Specify length-3 blocks using a template where the center element is not considered:
ArrayFilter[fun, {a, b, c, d, e, f}, {1, 0, 1}]Specify length-3 blocks using a template where only the left element is considered:
ArrayFilter[fun, {a, b, c, d, e, f}, {1, 0, 0}]Use DeleteMissing to remove elements according to a specified template:
ArrayFilter[fun[DeleteMissing[#]]&, {a, b, c, d, e, f}, {1, 0, 0}]Options (6)
Padding (6)
By default, fixed padding is used for neighborhoods at the border:
ArrayFilter[fun, {a, b, c, d, e, f}, 1]Pad neighborhoods using a constant value:
ArrayFilter[fun, {a, b, c, d, e, f}, 1, Padding -> 0]ArrayFilter[fun, {a, b, c, d, e, f}, 1, Padding -> "Periodic"]Periodic padding in all dimensions for a matrix:
ArrayFilter[fun, (| | | |
| -- | -- | -- |
| 11 | 12 | 13 |
| 21 | 22 | 23 |), 1, Padding -> "Periodic"]TraditionalForm[%]With Padding->None, ArrayFilter only visits neighborhoods entirely inside the array:
ArrayFilter[fun, {a, b, c, d}, 1, Padding -> None]Use padded values with different paddings:
ArrayFilter[fun, {a, b, c, d}, 1, Padding -> "Fixed"]With Padding->None, empty lists are returned when the neighborhood size is larger than the input:
ArrayFilter[fun, {a1, a2}, 1, Padding -> None]A 2x2 matrix has no 3x3 neighborhoods:
ArrayFilter[fun, {{a1, a2}, {b1, b2}}, 1, Padding -> None]A 2x2 matrix with a 1x3 template:
ArrayFilter[fun, {{a1, a2}, {b1, b2}}, {{1, 0, 1}}, Padding -> None]Applications (5)
Compute successive differences of elements:
ArrayFilter[Last[#] - First[#]&, {a, b, c, d, e, f}, 1]Compute a moving average with runs of 3 elements using a range-1 neighborhood:
ArrayFilter[Mean, {a, b, c, d, e}, 1]Compute a moving median of all values in each 3x3 neighborhood of a matrix:
f[neigh_] := Median[Flatten[neigh]];
ArrayFilter[f, {{1, 2, 4}, {5, 3, 1}, {1, 4, 2}, {3, 2, 0}}, 1]Compute a moving quantile for some data:
data = RandomFunction[WienerProcess[], {0, 10, 0.1}]["Values"];mq = ArrayFilter[Quantile[#, 0.75]&, data, 1];ListLinePlot[{data, mq}]Implement a 2D additive cellular automaton:
ArrayPlot /@ NestList[ArrayFilter[Mod[Total[#, 2], 2]&, #, {1, 1}]&, BoxMatrix[0, {11, 11}], 5]History
Text
Wolfram Research (2015), ArrayFilter, Wolfram Language function, https://reference.wolfram.com/language/ref/ArrayFilter.html.
CMS
Wolfram Language. 2015. "ArrayFilter." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ArrayFilter.html.
APA
Wolfram Language. (2015). ArrayFilter. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ArrayFilter.html
BibTeX
@misc{reference.wolfram_2026_arrayfilter, author="Wolfram Research", title="{ArrayFilter}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayFilter.html}", note=[Accessed: 15-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_arrayfilter, organization={Wolfram Research}, title={ArrayFilter}, year={2015}, url={https://reference.wolfram.com/language/ref/ArrayFilter.html}, note=[Accessed: 15-June-2026]}