fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 203: Calculate mean and standard deviation
Idiom # 203: Calculate mean and standard deviation
See
programming-idioms.org
:
Code
mean(a Sequence f64) => (sum a) / a.count.as_f64 stddev²(a Sequence f64) => m := mean a mean (a.map x->(x - m)**2) stddev(a Sequence f64) => f64.sqrt (stddev² a)
What are effects?
Running Example
ex203 is arr := [0.0, 8.0, 15.0, 47.0, 11.0] mean(a Sequence f64) => (sum a) / a.count.as_f64 stddev²(a Sequence f64) => m := mean a mean (a.map x->(x - m)**2) stddev(a Sequence f64) => f64.sqrt (stddev² a) say "mean of $arr is {mean arr}" say "stddev² of $arr is {stddev² arr}" say "stddev of $arr is {stddev arr}"
What are effects?
last changed: 2024-07-01
next: Idiom # 204: Return fraction and exponent of a real number