Calculating mean and standard deviation with std.algorithm.reduce
bearophile
bearophileHUGS at lycos.com
Wed Feb 13 06:53:33 PST 2013
jerro:
>> reduce!reducer(MQ(x.front, 0), zip(x, sequence!"n"))
>
> A small correction : you would need to use x.drop(1) instead of
> x, because the first element of x is only used to compute the
> initial value of 1. If you wanted k to have the same meaning as
> the one in your formula, you would need to use sequence!"n + 2"
> instead of sequence!"n".
See enumerate():
http://d.puremagic.com/issues/show_bug.cgi?id=5550
I think with enumerate it becomes:
MQ(x.front, 0).enumerate(1).reduce!reducer()
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list