[Numpy-discussion] 'Advanced' save and restore operation

Derek Homeier derek@astro.physik.uni-goettingen...
Mon Jan 23 19:00:16 CST 2012


On 24 Jan 2012, at 01:45, Olivier Delalleau wrote:

> Note sure if there's a better way, but you can do it with some custom load and save functions:
> 
> >>> with open('f.txt', 'w') as f:
> ...     f.write(str(x.dtype) + '\n')
> ...     numpy.savetxt(f, x)
> 
> >>> with open('f.txt') as f:
> ...     dtype = f.readline().strip()
> ...     y = numpy.loadtxt(f).astype(dtype)
> 
> I'm not sure how that'd work with structured arrays though. For the dict of parameters you'd have to write your own load/save piece of code too if you need a clean text file.
> 
> -=- Olivier
> 
> 2012/1/23 Emmanuel Mayssat <emayssat@gmail.com>
> After having saved data, I need to know/remember the data dtype to
> restore it correctly.
> Is there a way to save the dtype with the data?
> (I guess the header parameter of savedata could help, but they are
> only available in v2.0+ )
> 
> I would like to save several related structured array and a dictionary
> of parameters into a TEXT file.
> Is there an easy way to do that?
> (maybe xml file, or maybe archive zip file of other files, or ..... )
> 
> Any recommendation is helpful.

asciitable might be of some help, but to implement all of your required functionality, 
you'd probably still have to implement your own Reader class:

http://cxc.cfa.harvard.edu/contrib/asciitable/

Cheers,
						Derek



More information about the NumPy-Discussion mailing list