If I understand right, then yes, eachslice
allows only one “outer” dimension, meaning that your function will get N-1
-dimensional arrays when acting on an N
-array. Slightly confusingly mapslices
takes the “inner” dimensions as dims
instead, as do Slices
and slicemap
. But these should be more general:
julia> map(ndims, eachslice(ones(1,2,3), dims=3))
3-element Array{Int64,1}:
2
2
2
julia> mapslices(ndims, ones(1,2,3), dims=(1,2))
1×1×3 Array{Int64,3}:
[:, :, 1] =
2
[:, :, 2] =
2
[:, :, 3] =
2
julia> using JuliennedArrays
julia> map(ndims, Slices(ones(1,2,3), 1,2))
3-element Array{Int64,1}:
2
2
2
julia> using SliceMap
julia> slicemap(ndims, ones(1,2,3), dims=(1,2))
3-element Array{Int64,1}:
2
2
2
Here of course the function gives a scalar; had it made an array then the map
examples would be arrays of arrays, needing reduce(hcat,...
or Align
etc, which is built into mapslices
/ slicemap
.