[SciPy-User] Saving record arrays to tab formatted txt

Skipper Seabold jsseabold@gmail....
Tue Nov 10 16:00:47 CST 2009


On Nov 10, 2009, at 3:51 PM, David Baddeley  
<david_baddeley@yahoo.com.au> wrote:

> Hi all,
>
> does anyone know of an easy way to save record arrays as tab  
> formatted txt? numpy.savetxt doesn't do the trick.
>
> I've got a record array with nested records, and mixed data types -  
> dtype is as follows:
>
> dtype([('tIndex', '<i4'), ('fitResults', [('A', '<f4'), ('x0',  
> '<f4'), ('y0', '<f4'), ('sigma', '<f4'), ('background', '<f4'),  
> ('bx', '<f4'), ('by', '<f4')]), ('fitError', [('A', '<f4'), ('x0',  
> '<f4'), ('y0', '<f4'), ('sigma', '<f4'), ('background', '<f4'),  
> ('bx', '<f4'), ('by', '<f4')]), ('resultCode', '<i4'),  
> ('slicesUsed', [('x', [('start', '<i4'), ('stop', '<i4'), ('step',  
> '<i4')]), ('y', [('start', '<i4'), ('stop', '<i4'), ('step',  
> '<i4')]), ('z', [('start', '<i4'), ('stop', '<i4'), ('step',  
> '<i4')])])])
>
> and want to flatten it so that each entry in the table becomes a row  
> in the .txt file. ie:
>
> tIndex fitResults_A fitResults_x0 ....\n
> tIndex fitResults_A fitResults_x0 ....\n
> etc...
>
> If necessary I'll write my own code to format up a string for each  
> line, but thought I'd ask first in case anyone knew of a pre- 
> existing solution. It'd ideally be generic as I'm also likely to  
> want to use variations on the data type.
>
> many thanks,
> David
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

I have just been using savetxt as a template and adding processing as  
needed.  Would be interested in hearing any other solutions or  
extending savetxt to be more flexible / general.

-Skipper


More information about the SciPy-User mailing list