'Advanced' save and restore operation

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.
Regards, -- Emmanuel

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.
Regards,
Emmanuel _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

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

I know you wrote that you want "TEXT" files, but never-the-less, I'd like to point to http://code.google.com/p/h5py/ . There are viewers for hdf5 and it is stable and widely used.
Samuel
On 24.01.2012, at 00:26, Emmanuel Mayssat wrote:
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.
Regards,
Emmanuel _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
participants (4)
-
Derek Homeier
-
Emmanuel Mayssat
-
Olivier Delalleau
-
Samuel John