[SciPy-User] numpy: loadtxt with default value

Pierre GM pgmdevlist at gmail.com
Sat Aug 15 16:22:06 EDT 2009


On Aug 15, 2009, at 4:11 PM, Andreas Matthias wrote:

> The documentation of numpy.loadtxt says that the `converters'
> parameter can be used to provide a default value for missing
> data. However the following doesn't work.
>
>
> import numpy as np
> from StringIO import StringIO
>
> s = StringIO('111  222')
> a = np.loadtxt(s,
>               dtype = {'names': ('a', 'b', 'c'),
>                        'formats': (float, float, float)},
>               converters = {2: lambda s: float(s or 0)}
>               )
>
>
> What's wrong with this code?

You have only 2 columns in s, and gave the converter (and name and  
format) for a third one ?



More information about the SciPy-User mailing list