mapSlices

mapSlices(A, dim, callback)

Try it yourself:

See also:
map

mapSlices(): Transforming Matrix Slices

mapSlices() applies a function to slices of a matrix along selected dimensions. It is useful when work should happen row by row, column by column, or across higher-dimensional blocks rather than entry by entry.

Choose dimensions carefully

Know which axis represents observations and which represents features before mapping slices. Check shape with size(), and compare with map(), which processes individual entries. For row or column extraction, use row() and column().

Slice functions should return compatible outputs if they will be assembled into a matrix. Use mean() for per-slice summaries or sum() for aggregation.

Try Map Slices in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions