[SciPy-user] scipy.io.read_array: NaN in data file

Pierre GM pgmdevlist@gmail....
Tue Mar 10 11:14:40 CDT 2009


With the SVN version of Numpy:

 >>> import numpy as np
 >>> import StringIO

 >>> a = np.genfromtxtx(StringIO.StringIO("1, NaN"), delimiter=",")

If you want to output a MaskedArray:
 >>> a = np.genfromtxt(StringIO.StringIO("1, NaN"), delimiter=",",
                       missing="NaN", usemask=True)
 >>> isinstance(a, np.ma.MaskedArray)
True

On Mar 10, 2009, at 11:57 AM, Erik Granstedt wrote:

> Hello,
>
> I am using scipy.io.read_array to read in values from data files to
> arrays.  The data files occasionally contain "NaN"s, and I would like
> the returned array to also contain "NaN"s.  I've tried calling
> read_array with:
>
> scipy
> .io.read_array(file('read_array_test.dat','r'),missing=float('NaN'))
>
> but this still seems to convert the "NaN"s to 0.0
>
> Is there a way to get it to return "NaN"s in the array instead of
> converting them to 0.0 ?
>
> Thanks,
>
> -Erik
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list