[SciPy-User] Padded data structure
Warren Weckesser
warren.weckesser at enthought.com
Sun Feb 21 10:05:59 EST 2010
Miguel de Val Borro wrote:
> 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
>
Well, that's a nice surprise. It works for me too in 1.3.0. This
feature is not mentioned in the docstring in 1.3.0, so I didn't think to
try it.
Cheers,
Warren
> 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
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list