diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2007-05-12 19:58:43 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2007-05-12 19:58:43 +0000 |
commit | a7219199b9d566860b3653f60e87adc7006bb531 (patch) | |
tree | 693c46646d2af4e6059a43ad200d7ca315f022d7 /numpy/core/defmatrix.py | |
parent | 9fbf719d898ba9f3503afb454018a174706de760 (diff) | |
download | numpy-a7219199b9d566860b3653f60e87adc7006bb531.tar.gz |
Add/edit documentation for mean, std, var.
Diffstat (limited to 'numpy/core/defmatrix.py')
-rw-r--r-- | numpy/core/defmatrix.py | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py index 33efe2b99..1550d2444 100644 --- a/numpy/core/defmatrix.py +++ b/numpy/core/defmatrix.py @@ -241,12 +241,121 @@ class matrix(N.ndarray): return N.ndarray.sum(self, axis, dtype, out)._align(axis) def mean(self, axis=None, out=None): + """Compute the mean along the specified axis. + + Returns the average of the array elements. The average is taken over + the flattened array by default, otherwise over the specified axis. + + :Parameters: + axis : integer + Axis along which the means are computed. The default is + to compute the standard deviation of the flattened array. + dtype : type + Type to use in computing the means. For arrays of integer type + the default is float32, for arrays of float types it is the + same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. + + :Returns: + mean : The return type varies, see above. + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. + + :SeeAlso: + - var : variance + - std : standard deviation + + Notes + ----- + The mean is the sum of the elements along the axis divided by the + number of elements. + + """ return N.ndarray.mean(self, axis, out)._align(axis) def std(self, axis=None, dtype=None, out=None): + """Compute the standard deviation along the specified axis. + + Returns the standard deviation of the array elements, a measure of the + spread of a distribution. The standard deviation is computed for the + flattened array by default, otherwise over the specified axis. + + :Parameters: + axis : integer + Axis along which the standard deviation is computed. The + default is to compute the standard deviation of the flattened + array. + dtype : type + Type to use in computing the standard deviation. For arrays of + integer type the default is float32, for arrays of float types + it is the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. + + :Returns: + standard deviation : The return type varies, see above. + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. + + :SeeAlso: + - var : variance + - mean : average + + Notes + ----- + + The standard deviation is the square root of the average of the + squared deviations from the mean, i.e. var = sqrt(mean((x - + x.mean())**2)). The computed standard deviation is biased, i.e., the + mean is computed by dividing by the number of elements, N, rather + than by N-1. + + """ return N.ndarray.std(self, axis, dtype, out)._align(axis) def var(self, axis=None, dtype=None, out=None): + """Compute the variance along the specified axis. + + Returns the variance of the array elements, a measure of the spread of + a distribution. The variance is computed for the flattened array by + default, otherwise over the specified axis. + + :Parameters: + axis : integer + Axis along which the variance is computed. The default is to + compute the variance of the flattened array. + dtype : type + Type to use in computing the variance. For arrays of integer + type the default is float32, for arrays of float types it is + the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. + + :Returns: + variance : depends, see above + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. + + :SeeAlso: + - std : standard deviation + - mean : average + + Notes + ----- + + The variance is the average of the squared deviations from the mean, + i.e. var = mean((x - x.mean())**2). The computed variance is + biased, i.e., the mean is computed by dividing by the number of + elements, N, rather than by N-1. + + """ return N.ndarray.var(self, axis, dtype, out)._align(axis) def prod(self, axis=None, dtype=None, out=None): |