Next: , Previous: , Up: Internal Routines   [Contents][Index]

15.5.534 sdev

sdev(x [, mode, weights=weights, /sample, /population, /keepdims, /double, /omitnans])

By default, this function returns the sample standard deviation of numerical array x.

If mode is a scalar or an array with a size different from that of x, then it indicates the dimension(s) along which standard deviations are calculated for each combination of the remaining coordinates. In that case, if also /keepdims is specified, then the dimension(s) along which the deviations are calculated are set to 1 in the result. If /keepdims is not set, then such dimensions are omitted from the result, and if only a single number is returned, then it is returned as a scalar.

If mode is an array with the same number of elements as x, then each element of mode identifies the (scalar) class to which each corresponding element of x belongs, and then a standard deviation is returned for each class. The first element of the result refers to class 0 (if no class is negative), or to the most negative class.

If weights is specified, then it must be a numerical array with the same dimensions as x (or merely the same number of elements, if deviations are calculated by class), and then each of its elements indicates the weight of the corresponding element of x, and then weighted standard deviations are returned. The weights are copied to a version with the same data type as x for the internal calculations (except that the copy is kept real even if x is complex).

If /population or weights are specified, then population standard deviations are returned. Otherwise, sample standard deviations are returned.

If /omitnans is specified, then data elements and weights that are equal to NaN are omitted from the calculations.

Complex numbers are supported.

The result has type double if x is itself double or cdouble, or if /double was specified. Otherwise, the result has type float.

The last calculated standard deviation is stored in !lastsdev, and the associated average (or the real part of it, for complex arguments) in !lastmean (except if the standard deviations were determined by class).

Examples, with x = [[[6, 4, 3]],[[8, 2, 4]]] and c = [2, 2, 2, 2, 1, 1]:

To print the population standard deviation along the first dimension (dimension 0, rows) of x:

      1.247219      2.494438

And along the second dimension (dimension 1, columns):

             1             1           0.5

To divide each column of x by its sample standard deviation:

LUX>x /= sdev(x,1,/keepdims)
      4.242641      2.828427      4.242641
      5.656854      1.414214      5.656854

To print the population standard deviation of x for the classes identified by c:

             0      1.414214      2.217356

Class 0 yields 0 because there are no elements 0 in c. Class 1 yields the population standard deviation (1.414214) of elements 2, 4, and class 2 yield the deviation (2.217356) of elements 6, 4, 3, 8.

See also: hist, mean, total, variance, !lastmean, !lastsdev

Next: , Previous: , Up: Internal Routines   [Contents][Index]