Averages/Root mean square: Difference between revisions

m
Line 612:
There are a variety of ways to do this via built-in functions in Julia, given an array <code>A = [1:10]</code> of values. The formula can be implemented directly as:
<lang julia>sqrt(sum(A.^2.) / length(A))</lang>
or shorter (and as spoken: root-mean-square)
<lang julia>sqrt(mean(A.^2.))</lang>
or the implicit allocation of a new array by <code>A.^2.</code> can be avoided by using <code>sum</code> as a higher-order function: <lang julia>sqrt(sum(x -> x*x, A) / length(A))</lang>
One can also use an explicit loop for near-C performance
2

edits