Standard Library function that returns theaverage value of an array. Optionally, it can return the average value of one dimension of an array.
dim (optional) The specific dimension of array that will be averaged. Must be a number that is in the range 0 dim < n, where n is the number of dimensions in array.
If dim is specified, result is an array containing the average values for all elements of the specified dimension.
The optional parameter dim allows you to find the average values for one dimension of array rather than the whole array. The first dimension in the array is denoted by 0, the second dimension by 1, and so on.
If the dimension you specify is not valid for array, the input array is returned as the result.
array = INTARR(3, 4) array(*, 0) = [5, 7, 9] array(*, 1) = [2, 8, 5] array(*, 2) = [3, 4, 8] array(*, 3) = [3, 3, 3] PRINT, AVG(array)
5.00000
PRINT, AVG(array, 0)
7 5 5 3
PRINT, AVG(array, 1)
3 5 6
Array
has dimensions of (3,4,5)
, then the command
avg_dim = AVG(array, 1)
avg_dim = FLTARR(3, 5) FOR j = 0,4 DO BEGIN
FOR i = 0,2 DO BEGIN
avg_dim(i,j) = TOTAL(array(i,*,j)) / 4.
ENDFOR
ENDFOR