Skip to content

MovingMap ​

f applied to each width-(w+1) window of list, sliding by 1 with no padding.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageMovingMap!
MovingMap(f, list, w)f applied to each window {list[i], …, list[i+w]} -- Length(list) - w results
Typed signatures
TypePackageApplies
((collection<any>) -> any, collection<any>, integer) -> collectioncombinatoricsalways

Domain: Collections

Details
  • Same as Map(f, Partition(list, w + 1, 1)) -- no boundary padding or clipping, unlike a centered-radius window.

Examples

Basic #

Each width-2 window has length 2 -- three windows from a 4-element list

live ↗
InMovingMap(Length,[1,2,3,4],1)\mathrm{MovingMap}(\mathrm{Length}, \bigl\lbrack1, 2, 3, 4\bigr\rbrack, 1)Out[2,2,2]\bigl\lbrack2, 2, 2\bigr\rbrack

A window of width three slides along the list, averaging each

live ↗
InMovingMap(Mean,[x1,x2,x3,x4,x5],2)\mathrm{MovingMap}(\mathrm{Mean}, \bigl\lbrack x_1, x_2, x_3, x_4, x_5\bigr\rbrack, 2)Out[x1+x2+x33,x2+x3+x43,x3+x4+x53]\bigl\lbrack\frac{x_1+x_2+x_3}{3}, \frac{x_2+x_3+x_4}{3}, \frac{x_3+x_4+x_5}{3}\bigr\rbrack
live ↗
InMovingMap(Total,[1,2,3,4,5],2)\mathrm{MovingMap}(\mathrm{Total}, \bigl\lbrack1, 2, 3, 4, 5\bigr\rbrack, 2)Out[6,9,12]\bigl\lbrack6, 9, 12\bigr\rbrack
Scope #
live ↗
InMovingMap(f,data,2)\mathrm{MovingMap}(f, \mathrm{data}, 2)OutMovingMap(f,data,2)\mathrm{MovingMap}(f, \mathrm{data}, 2)
live ↗
InMovingMap(f,v,2)\mathrm{MovingMap}(f, v, 2)OutMovingMap(f,v,2)\mathrm{MovingMap}(f, v, 2)
Properties #
live ↗
InMovingMap(()↦Last(_1⁡)−First(_1⁡),data,1)\mathrm{MovingMap}(()↦\mathrm{Last}(\operatorname{\_1})-\mathrm{First}(\operatorname{\_1}), \mathrm{data}, 1)OutMovingMap(()↦Last(_1⁡)−First(_1⁡),data,1)\mathrm{MovingMap}(()↦\mathrm{Last}(\operatorname{\_1})-\mathrm{First}(\operatorname{\_1}), \mathrm{data}, 1)
About
Examples6
Checked againstWolfram Language 3 agree3 differ
CrosswalkWolfram Language