[Numpy-discussion] None as missing value

Pierre GM pgmdevlist at mailcan.com
Mon Jul 3 02:01:30 EDT 2006


Keith,

> > Is there something better than None to represent missing values so
> > that when I convert to numpy arrays (actually matrices) I'll be all
> > set? (I could use -99, but that would be even more embarrassing than
> > my python skills.)

As Tim suggested, have a look at the masked array module. However, the result 
will NOT be exportable to matrices, unless you fill the missing value first 
(for example, with -99 ;)). I use MaskedArrays a lot, they're quite flexible.

An alternative would be to use nan instead of None:
>>> import numpy as N
>>> x = [[1, nan], [2, 3]]
>>> print N.matrix(x)
[[ 1.                 nan]
 [ 2.          3.        ]]

Of course, the solution will depend on what you need...




More information about the NumPy-Discussion mailing list