Averages/Arithmetic mean: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Fortran}}: langtag) |
||
Line 174: | Line 174: | ||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
In ISO Fortran 90 or later, use the SUM intrinsic, the SIZE intrinsic and the MAX intrinsic (to avoid divide by zero): |
In ISO Fortran 90 or later, use the SUM intrinsic, the SIZE intrinsic and the MAX intrinsic (to avoid divide by zero): |
||
real, target, dimension(100) :: a = (/ (i, i=1, 100) /) |
<lang fortran> real, target, dimension(100) :: a = (/ (i, i=1, 100) /) |
||
real, dimension(5,20) :: b = reshape( a, (/ 5,20 /) ) |
real, dimension(5,20) :: b = reshape( a, (/ 5,20 /) ) |
||
real, pointer, dimension(:) :: p => a(2:1) ! pointer to zero-length array |
real, pointer, dimension(:) :: p => a(2:1) ! pointer to zero-length array |
||
Line 193: | Line 193: | ||
! dividing by the length of the row, which is the number of columns (SIZE of dimension 2) |
! dividing by the length of the row, which is the number of columns (SIZE of dimension 2) |
||
colmeans = sum(b,2)/max(size(b,1),1) ! SUM elements in each column (dimension 2) |
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) |
! dividing by the length of the column, which is the number of rows (SIZE of dimension 1)</lang> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |