
dim_avg_n
Computes the average of a variable's given dimension(s) at all other dimensions.
Prototype
function dim_avg_n ( x : numeric, dims [*] : integer ) return_val : float or double
Arguments
xA variable of numeric type and any dimensionality.
dimsThe dimension(s) of x on which to calculate the average. Must be consecutive and monotonically increasing.
Return value
The output will be double if x is double, and float otherwise.
The output dimensionality will be the same as all but dims' dimensions of the input variable. The dimension rank of the input variable will be reduced by the rank of dims.
Description
The dim_avg_n function computes the average of all elements of the dimensions indicated by dims for each index of all other dimensions. Missing values are ignored.
Use the dim_avg_n_Wrap function if metadata retention is desired. The interface is identical.
See Also
dim_avg_n_Wrap, avg, dim_avg, dim_median_n, dim_stddev_n, dim_num_n, dim_product_n, dim_rmsd_n, dim_rmvmean_n, dim_rmvmed_n, dim_standardize_n, dim_stat4_n, dim_stddev_n, dim_sum_n, dim_variance_n
Examples
Example 1
Create a variable (q) of size (3,5,10) array. Then calculate the average of the rightmost dimension.
q = random_uniform(-20,100,(/3,5,10/)) qAvg = dim_avg_n(q,2) ;==> qAvg(3,5) ; Use dim_avg_n_Wrap if metadata retention is desired ; qAvg = dim_avg_n_Wrap(q,2) ;==> qAvg(3,5)Example 2
Let z be of size (ntim,nlat,mlon) and with named dimensions "time", "lat" and "lon", respectively. Then, for each time and latitude, the zonal mean (ie, average of all non-missing longitudes) is:
zAvgLon = dim_avg_n( z, 2 ) ; ==> zAvgLon(ntim,nlat) ; Use dim_avg_n_Wrap if metadata retention is desired ; zAvgLon = dim_avg_n_Wrap( z, 2 ) ; ==> zAvgLon(ntim,nlat)Example 3
Let z be defined as in example 2: z(time,lat,lon). Compute the time average at each latitude/longitude grid point.
zAvgTime = dim_avg_n( z, 0) ) ; ==> zAvgTime(nlat,nlon) ; Use dim_avg_n_Wrap if metadata retention is desired ; zAvgTime = dim_avg_n_Wrap( z, 0) ) ; ==> zAvgTime(nlat,nlon)Example 4
Let z be defined as z(time,lev,lat,lon). Compute the time average at each latitude/longitude grid point.
zAvg = dim_avg_n(z, (/0,1/)) ; ==> zAvg(nlat,nlon) ; Use dim_avg_n_Wrap if metadata retention is desired ; zAvg = dim_avg_n_Wrap(z, (/0,1/)) ; ==> zAvg(nlat,nlon)