[Numpy-discussion] None as missing value

Tim Leslie tim.leslie at gmail.com
Mon Jul 3 01:46:12 EDT 2006


On 7/3/06, Keith Goodman <kwgoodman at gmail.com> wrote:
> I have a list x
>
> >> x
> [[1, None], [2, 3]]
>
> that I generate outside of numpy (with plain python). What is the best
> way to convert x into an array? This doesn't work
>
> >> asarray(x)
>
> array([[1, None],
>        [2, 3]], dtype=object)   <-- I'm hoping for something like dtype=float64
>
> 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.)
>
> If there is nothing better than None, what's a fast way to take care
> of the None's if x is faily large?

You might want to have a look at the masked array module in numpy
(numpy.ma). The following example might help to get you started.

>>> import numpy as N
>>> x = [[1, None], [2, 3]]
>>> m = N.ma.array(x, mask=N.equal(x, None))
>>> print m
[[1 --]
 [2 3]]


Cheers,

Tim

>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the NumPy-Discussion mailing list