[Numpy-discussion] save a matrix

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


On 11/30/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
> It is also possible to put the variables of interest in a dictionary, then
> pickle the dictionary. That way you can also store the variable names.
>
> In [27]: f = open(' dump.pkl','w')
>
> In [28]: pickle.dump( {'a':a,'b':b}, f)
>
> In [29]: f.close()
>
>  In [30]: f = open('dump.pkl','r')
>
> In [31]: mystuff = pickle.load(f)
>
> In [32]: f.close()
>
>  In [34]: mystuff
> Out[34]:
>  {'a': matrix([[2, 3],
>         [4, 5]]), 'b': matrix([[2, 3],
>         [4, 5]])}

I think I could use that to write a function savematrix(filename, a, b, c,...)

Is there a way to write a loadmatrix(filename) that doesn't return
anything but makes the matrices a, b, c, ... available?

Probably not a good function design. But useful for quick things.


More information about the Numpy-discussion mailing list