Skip to the navigation links
Last modified: June 2010

AHELP for CIAO 4.2


Context: sl.ciao_contrib


Calculate several basic statistic values for a data array




The simple_stats() routine calculates several simple statistics for the input data (the array argument), such as the mean, median, and standard deviation. For more control over the calculation use the statistics module.

Loading the routine

The routine can be loaded into Sherpa by saying:

require ("ciao_utils");


Name Description
array The array of data used to calculate the statistic values.

The return value

The return value is an object with the following fields:

Field Value
npts The number of elements in the array.
min The minimum value in the array.
max The maximum value in the array.
total The sum of all the array elements.
mean The mean value of the array.
median The median value of the array.
stddev The standard deviation of the array, calculated using the biased estimator (so the mean level is calculated using the number of elements and not "number of elements - 1").

Example 1

chips> x = [0, 1, 2, 3, 2, 3, 4, 2, 1, 5];
chips> s = simple_stats(x);

The return value of s is an object which contains the calculated statistics of the array:

chips> print (s);
npts   = 10
min    = 0
max    = 5
total  = 23
mean   = 2.3
median = 2.0
stddev = 1.41774468788
chips> vmessage("The mean is %g +- %g", s.mean, s.stddev);
The mean is 2.3 +- 1.41774

Example 2

chips> img = read_image("emap.fits");
chips> ivals = get_imagevals(img);
chips> ix = where(isinf(ivals) | isnan(ivals) == 0);
chips> simg = simple_stats(ivals[ix];

Here we use the Crates read_image() and get_imagevals() to read in the contents of the image "emap.fits". Since it may contain "invalid" numbers, such as NaN and Infinity, we filter out these values before calculating the statistics (simg).


The version scheme has changed to a date-based system. There should be no changes to the behavior of this routine.

See Also


Last modified: June 2010