Averages/Arithmetic mean: Difference between revisions

(→‎{{header|Haskell}}: ++ gnu octave)
Line 223:
colmeans = sum(b,2)/max(size(b,1),1) ! SUM elements in each column (dimension 2)
! 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}}==