Scipy & Ipython 笔记本:如何保存和加载结果?

Scipy & Ipython Notebook: how to save and load results?

现在我正在使用 Ipython 笔记本。 我的部分程序需要很长时间才能得到结果,所以我想保存结果并在下次使用脚本时加载它。否则我需要重复计算,需要很多时间。

我想知道 saving and load 结果有什么好的做法吗?这让我下次需要时更容易恢复脚本?

保存text结果很容易,但在scipynumpy中,结果可能相当复杂,例如matrix, numerical array.

有几个选项,比如pickle, which allows you to save almost anything. However, if what you are going to save are numeric numpy arrays/matices, np.save and np.load似乎更合适。

data = # my data np array
np.save('mypath', data)
data = np.load('mypath')