[Numpy-discussion] save a matrix

Keith Goodman kwgoodman at gmail.com
Thu Nov 30 23:17:29 CST 2006


On 11/30/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
> On 11/30/06, Keith Goodman <kwgoodman at gmail.com> wrote:
> > What's a good way to save matrix objects to file for later use? I just
> > need something quick for debugging.
> >
> > I saw two suggestions on this list from Francesc Altet (2006-05-22):
> >
> > 1. Use tofile and fromfile and save the meta data yourself.
> >
> > 2. pytables
> >
> > Any suggestions for #3?
> Is this what you want?
>
> In [14]: a
>  Out[14]:
> matrix([[2, 3],
>          [4, 5]])
>
> In [15]: b
>  Out[15]:
> matrix([[2, 3],
>          [4, 5]])
>
> In [16]: f = open(' dump.pkl','w')
>
> In [17]: pickle.dump(a,f)
>
> In [18]: pickle.dump(b,f)
>
>  In [19]: f.close()
>
>  In [20]: f = open('dump.pkl','r')
>
> In [21]: x = pickle.load(f)
>
> In [22]: y = pickle.load(f)
>
>  In [23]: f.close()
>
>  In [24]: x
> Out[24]:
>  matrix([[2, 3],
>         [4, 5]])
>
>  In [25]: y
> Out[25]:
>  matrix([[2, 3],
>         [4, 5]])

Yes. That will do very well.

You got me out of a pickle.


More information about the Numpy-discussion mailing list