[Numpy-discussion] Clarifications in numpy.ma module

Alexander Belopolsky ndarray at mac.com
Tue Dec 30 15:29:40 EST 2014

On Tue, Dec 30, 2014 at 2:49 PM, Benjamin Root <ben.root at ou.edu> wrote:

> Where does it say that operations on masked arrays should not produce NaNs?

Masked arrays were invented with the specific goal to avoid carrying NaNs
in computations.  Back in the days, NaNs were not available on some
platforms and had significant performance issues on others.  These days NaN
support for floating point types is nearly universal, but numpy types are
not limited by floating point.

> Having np.mean([]) return the same thing as np.ma.mean([]) makes complete

Does the following make sense as well?

>>> import numpy
>>> numpy.ma.masked_values([0, 0], 0).mean()
>>> numpy.ma.masked_values([0], 0).mean()
>>> numpy.ma.masked_values([], 0).mean()
* Two warnings *
masked_array(data = nan,
             mask = False,
       fill_value = 0.0)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141230/ef53aed0/attachment.html>

More information about the NumPy-Discussion mailing list