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

David Baddeley david_baddeley@yahoo.com...
Tue Nov 10 14:51:14 CST 2009


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


      


More information about the SciPy-User mailing list