Making mapslices drop dimensions for scalars results automatially

question

#1

In a sense, I am looking for a workaround for #16606: for functions which return an array, I would like to keep it as is, but for functions which return a scalar, I would like to drop the relevant dimension. I can’t just apply dropdims automatically, eg

using Statistics
R = randn(100, 5)
mapslices(col -> quantile(col, [0.25, 0.5, 0.75]), R; dims = 1) # size (3, 5), OK
mapslices(col -> quantile(col, [0.5]), R; dims = 1)             # size (1, 5), OK
mapslices(mean, R; dims = 1)                                    # size (1, 5), I want (5, )

#2

On Julia 1.1, you can use map(mean, eachslice(R, dims=1)). Now, that won’t do the concatenating behavior in the other cases (it’ll make an array of arrays), but I find that much easier to reason about. :slight_smile: