[Numpy-discussion] Efficient way to handle None->nan?

Sasha ndarray at mac.com
Wed Jan 18 16:11:13 CST 2006

>>> from numpy.core.ma import masked_values
>>> from numpy import nan
>>> masked_values([1.0,None,2.0],None).filled(nan).astype(float)
array([ 1.        ,         nan,  2.        ])

On 1/18/06, Russell E. Owen <rowen at cesmail.net> wrote:
> We're getting numeric data from a (MySQL) database. We'd like to use
> numarray or NumPy on the resulting data, but some values may be None. Is
> there a fast, efficient way to replace None with NaN? I'd hate to use a
> list comprehension on each data tuple before turning it into an array,
> but I haven't thought of anything else.
> numarray.array and numarray.where are both intolerant of None in the
> input data.
> -- Russell
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&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