Chris@87: """ Chris@87: ============= Chris@87: Masked Arrays Chris@87: ============= Chris@87: Chris@87: Arrays sometimes contain invalid or missing data. When doing operations Chris@87: on such arrays, we wish to suppress invalid values, which is the purpose masked Chris@87: arrays fulfill (an example of typical use is given below). Chris@87: Chris@87: For example, examine the following array: Chris@87: Chris@87: >>> x = np.array([2, 1, 3, np.nan, 5, 2, 3, np.nan]) Chris@87: Chris@87: When we try to calculate the mean of the data, the result is undetermined: Chris@87: Chris@87: >>> np.mean(x) Chris@87: nan Chris@87: Chris@87: The mean is calculated using roughly ``np.sum(x)/len(x)``, but since Chris@87: any number added to ``NaN`` [1]_ produces ``NaN``, this doesn't work. Enter Chris@87: masked arrays: Chris@87: Chris@87: >>> m = np.ma.masked_array(x, np.isnan(x)) Chris@87: >>> m Chris@87: masked_array(data = [2.0 1.0 3.0 -- 5.0 2.0 3.0 --], Chris@87: mask = [False False False True False False False True], Chris@87: fill_value=1e+20) Chris@87: Chris@87: Here, we construct a masked array that suppress all ``NaN`` values. We Chris@87: may now proceed to calculate the mean of the other values: Chris@87: Chris@87: >>> np.mean(m) Chris@87: 2.6666666666666665 Chris@87: Chris@87: .. [1] Not-a-Number, a floating point value that is the result of an Chris@87: invalid operation. Chris@87: Chris@87: """ Chris@87: from __future__ import division, absolute_import, print_function Chris@87: Chris@87: __author__ = "Pierre GF Gerard-Marchant ($Author: jarrod.millman $)" Chris@87: __version__ = '1.0' Chris@87: __revision__ = "$Revision: 3473 $" Chris@87: __date__ = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $' Chris@87: Chris@87: from . import core Chris@87: from .core import * Chris@87: Chris@87: from . import extras Chris@87: from .extras import * Chris@87: Chris@87: __all__ = ['core', 'extras'] Chris@87: __all__ += core.__all__ Chris@87: __all__ += extras.__all__ Chris@87: Chris@87: from numpy.testing import Tester Chris@87: test = Tester().test Chris@87: bench = Tester().bench