package documentation

Arrays sometimes contain invalid or missing data. When doing operations on such arrays, we wish to suppress invalid values, which is the purpose masked arrays fulfill (an example of typical use is given below).

For example, examine the following array:

>>> x = np.array([2, 1, 3, np.nan, 5, 2, 3, np.nan])

When we try to calculate the mean of the data, the result is undetermined:

>>> np.mean(x)

The mean is calculated using roughly np.sum(x)/len(x), but since any number added to NaN [1] produces NaN, this doesn't work. Enter masked arrays:

>>> m =, np.isnan(x))
>>> m
masked_array(data = [2.0 1.0 3.0 -- 5.0 2.0 3.0 --],
      mask = [False False False  True False False False  True],

Here, we construct a masked array that suppress all NaN values. We may now proceed to calculate the mean of the other values:

>>> np.mean(m)
[1]Not-a-Number, a floating point value that is the result of an invalid operation.
Module bench Undocumented
Module core : a package to handle missing or invalid values.
Module extras Masked arrays add-ons.
Module mrecords
Module setup Undocumented
Package tests No package docstring; 5/7 modules documented
Module testutils Miscellaneous functions for testing masked arrays and subclasses
Module timer​_comparison Undocumented


Variable test Undocumented
test =