BlockMap

BlockMap[f,list,n]

applies f to non-overlapping sublists of length n in list.

BlockMap[f,list,n,d]

applies f to sublists with offset d in list.

BlockMap[f,list,{n1,n2,},]

applies f to blocks of size n1×n2×.

Details

Examples

open allclose all

Basic Examples  (4)

Apply a function to all non-overlapping, length-2 sublists:

Apply a function to overlapping sublists of length 2 with offset 1:

Apply a function to a matrix:

Apply a function to all 2x2 sub-matrices:

Scope  (7)

Apply a function to a ragged array:

Apply a function to blocks of size {2,1,2} of a rank-3 array:

Specify an offset {1,2} with a block size {2,2} to allow overlapping for rows but not for columns:

Skip elements by using an offset larger than the block size:

Incomplete sublists at the end are dropped:

The head need not be List:

BlockMap works with SparseArray objects:

Applications  (5)

Compute successive differences of elements:

Compute a moving average with runs of 3 elements:

Compute a moving median of a matrix:

Compute a moving quantile for some data:

Smooth a simulated particle trajectory:

The underlying signal and simulated path with noise:

Smooth the trajectory using a moving TrimmedMean:

Increasing the window size gives a smoother trajectory:

Properties & Relations  (2)

BlockMap is effectively the same as using Map and Partition:

BlockMap need not construct all the sublists and requires less memory:

ListCorrelate[ker,list] effectively combines ker with a sliding block in list:

Use an offset of 1 in BlockMap to apply the function to overlapping segments the length of ker:

ListConvolve is similar except the kernel is reversed:

Wolfram Research (2015), BlockMap, Wolfram Language function, https://reference.wolfram.com/language/ref/BlockMap.html.

Text

Wolfram Research (2015), BlockMap, Wolfram Language function, https://reference.wolfram.com/language/ref/BlockMap.html.

CMS

Wolfram Language. 2015. "BlockMap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/BlockMap.html.

APA

Wolfram Language. (2015). BlockMap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/BlockMap.html

BibTeX

@misc{reference.wolfram_2024_blockmap, author="Wolfram Research", title="{BlockMap}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/BlockMap.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_blockmap, organization={Wolfram Research}, title={BlockMap}, year={2015}, url={https://reference.wolfram.com/language/ref/BlockMap.html}, note=[Accessed: 22-November-2024 ]}