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

Olivier Delalleau shish at keba.be
Mon Jan 23 19:45:09 EST 2012


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 at 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120123/113c608a/attachment.html>


More information about the NumPy-Discussion mailing list