What about the following?
(f(x) for x in a)
# this may be some indexable view of a special type that can be
# passed as arguments, such that we can do
sum(f(x) for x in a)
In this way, statistics can be easily implemented in an efficient way, for example
var(a) = sum(abs2(x - mean(x)) for x in a) / (length(a) - 1)
This is a one-liner, but it does not create any temporary arrays.
If the Cartesian iteration discussed in #1917 can be implemented, this would become even more powerful:
# weighted mean
wmean(a, ws) = dot(a, ws) / sum(ws)
# weighted variance
wvar(a, ws) = sum(abs2(x - mean(x)) * w for (x, w) in (a, ws)...)
What about the following?
In this way, statistics can be easily implemented in an efficient way, for example
This is a one-liner, but it does not create any temporary arrays.
If the Cartesian iteration discussed in #1917 can be implemented, this would become even more powerful: