Applying `quantile` to `AbstractArray`s

statistics

#1

The docstring of quantile in the Statistics module says:

quantile(itr, p; sorted=false)

Compute the quantile(s) of a collection itr at a specified probability or vector or tuple of
probabilities p on the interval [0,1]. The keyword argument sorted indicates whether
itr can be assumed to be sorted.

But itr cannot actually be any iterable; only <:AbstractVector or something that becomes that type after collect, as seen in the “in-place” function quantile! For instance, a Matrix or more generally an AbstractArray{T,N} where N > 1 is not accepted.

What would be the best way to calculate quantiles for such variables?

An obvious option is quantile(x[:], p), but this makes an unnecessary copy.

quantile(view(x,:), p) would avoid the copy, but I don’t know if there something better.


#2

Probably best to submit a PR for supporting an iterable version. Currently, I guess

quantile(vec(x), p)