[SciPy-User] Padded data structure

Miguel de Val Borro miguel.deval@gmail....
Sun Feb 21 03:24:31 CST 2010


On Sun, Feb 21, 2010 at 02:02:09AM -0600, Warren Weckesser wrote:
> Miguel de Val Borro wrote:
> >On Sat, Feb 20, 2010 at 10:55:59PM -0800, Christopher Barker wrote:
> >>>I would like to read padded output files from C structures that look
> >>>like this file:
> >>>http://spec.jpl.nasa.gov/ftp/pub/catalog/catdir.cat The second
> >>>row is a 13 character string that contains whitespaces.  I
> >>>have looked at the align option in dtype passed as a parameter to
> >>>loadtxt but could not make it work.
> >>Since there is whitespace between all those columns, I don't
> >>think you need align.  I suspect that a dtype something like:
> >>
> >>('i4', 'S13', 'i4', 'f8', 'f8','f8','f8','f8','f8','f8', 'i2')
> >
> >The problem is that the S13 string contains whitespaces, which is also
> >the separator between columns. Using this dtype I get the error:
> >
> >ValueError: invalid literal for float(): v2,2v2,v
> >
> 
> Any chance you can upgrade your numpy version to the current trunk?
> Somewhere between version 1.3.0 and the current trunk, the
> 'delimiter' argument of genfromtxt() was enhanced to accept a list
> of field widths.  The attached script shows how it can be used to
> read the file "catdir.dat".

Thank you very much for the script, it does exactly what I needed.
Actually genfromtxt accepts field widths also in numpy 1.3.0 shipped
with Ubuntu 9.10. It looks like the function is not easy to find in the
documentation, althought this may be already fixed in the repository.

Miguel


More information about the SciPy-User mailing list