__init__.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. """
  2. =============
  3. Masked Arrays
  4. =============
  5. Arrays sometimes contain invalid or missing data. When doing operations
  6. on such arrays, we wish to suppress invalid values, which is the purpose masked
  7. arrays fulfill (an example of typical use is given below).
  8. For example, examine the following array:
  9. >>> x = np.array([2, 1, 3, np.nan, 5, 2, 3, np.nan])
  10. When we try to calculate the mean of the data, the result is undetermined:
  11. >>> np.mean(x)
  12. nan
  13. The mean is calculated using roughly ``np.sum(x)/len(x)``, but since
  14. any number added to ``NaN`` [1]_ produces ``NaN``, this doesn't work. Enter
  15. masked arrays:
  16. >>> m = np.ma.masked_array(x, np.isnan(x))
  17. >>> m
  18. masked_array(data = [2.0 1.0 3.0 -- 5.0 2.0 3.0 --],
  19. mask = [False False False True False False False True],
  20. fill_value=1e+20)
  21. Here, we construct a masked array that suppress all ``NaN`` values. We
  22. may now proceed to calculate the mean of the other values:
  23. >>> np.mean(m)
  24. 2.6666666666666665
  25. .. [1] Not-a-Number, a floating point value that is the result of an
  26. invalid operation.
  27. .. moduleauthor:: Pierre Gerard-Marchant
  28. .. moduleauthor:: Jarrod Millman
  29. """
  30. from . import core
  31. from .core import *
  32. from . import extras
  33. from .extras import *
  34. __all__ = ['core', 'extras']
  35. __all__ += core.__all__
  36. __all__ += extras.__all__
  37. from numpy._pytesttester import PytestTester
  38. test = PytestTester(__name__)
  39. del PytestTester