I'm new to Python and I'm eagerly migrating from MATLAB to IPython as my preferred language for data analysis at the lab.
In MATLAB, after a session of data crunching, I would do
>>> save('myresults.mat','x','y','z');
and save the results of the variables x, y and z in a file called 'myresults.mat'. Later on, I could simply say:
>>> load('myresults');
and MATLAB would load the .mat file AND assign the stored values of the variables to the current workspace.
I've recently learned that I can do similarly for IPython using numpy, namely:
import numpy as np
a = 2
b = np.sqrt(2)
np.savez('myresultsinpython',a,b)
and later do something like
npzfile = np.load('myresultsinpython')
However, what I get is an object from which I can access my variables by:
npzfile['arr_1']
etc., but I loose all info on the original names of the variables. I know I could save the file by doing
np.savez('myresultsinpython',a=a,b=b)
but this is not that useful, as I still have to do something like:
npzfile['a']
to access the variable's value.
How do I both load the file and have the variables created in my workspace and their values assigned according to the values stored in the file?
Something like np.load('myresults')
and be able to do a+b
and get 3.4142135623730949 (=2+sqrt(2))
in return.