[SciPy-user] NaN's in numpy (and Scipy)

Pierre GM pgmdevlist at gmail.com
Sat Jan 6 15:25:56 CST 2007

On Saturday 06 January 2007 16:08, Alan Jackson wrote:
> Missing data. Basically want to handle missing data as painlessly as
> possible without having to add a bunch of stuff every time a calculation is
> done.

Could you be a bit more specific about you mean by this "bunch of stuffs" ? 
What are your complaints about the current implementation of masked arrays ?
Assuming you have Nan in your data, you can get a masked array as easily as
>>> import numpy as N
>>> import numpy.core.ma as MA
>>> x = N.array([1,2,N.nan,4])
>>> X = MA.masked_array(x, mask=N.isnan(x)
>>> X
array(data = 
 [  1.00000000e+00   2.00000000e+00   1.00000000e+20   4.00000000e+00],
      mask =
 [False False True False],

And then you can play with X.

A few months ago, I ran into some problems while trying to subclass 
MaskedArray. I rewrote most of numpy.core.ma to solve my particular issues.
This new implementation is available on the scipy SVN server, in the 
sandbox/maskedarray folder. I'd be glad if you could give it a try, so that I 
could improve it.

More information about the SciPy-user mailing list