__init__.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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, extras
  31. from .core import *
  32. from .extras import *
  33. __all__ = ['core', 'extras']
  34. __all__ += core.__all__
  35. __all__ += extras.__all__
  36. from numpy._pytesttester import PytestTester
  37. test = PytestTester(__name__)
  38. del PytestTester