Anonymous user
Averages/Arithmetic mean: Difference between revisions
m
oct...
(→{{header|Haskell}}: ++ gnu octave) |
m (oct...) |
||
Line 224:
! dividing by the length of the column, which is the number of rows (SIZE of dimension 1)</lang>
=={{header|GNU Octave}}==▼
GNU Octave has a <tt>mean</tt> function (from statistics package), but it does not handle an empty vector; an implementation that allows that is:▼
<lang octave>function m = omean(l)▼
if ( numel(l) == 0 )▼
m = 0;▼
else▼
m = mean(l);▼
endif▼
endfunction▼
disp(omean([]));▼
disp(omean([1,2,3]));</lang>▼
=={{header|Haskell}}==
Line 408 ⟶ 394:
(float total /. length)
;;</lang>
▲GNU Octave has a <tt>mean</tt> function (from statistics package), but it does not handle an empty vector; an implementation that allows that is:
▲<lang octave>function m = omean(l)
▲ if ( numel(l) == 0 )
▲ m = 0;
▲ else
▲ m = mean(l);
▲ endif
▲endfunction
▲disp(omean([]));
▲disp(omean([1,2,3]));</lang>
=={{header|Perl}}==
|