ZK Zhao
ZK Zhao

Reputation: 21583

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

Now I'm using Ipython Notebook. There is part of my program need a long time to get the result, so I want to save the result and load it when next time I use the script. Otherwise I need to repeat the calculation and need a lot time for this.

I'm wondering is there any good practice of saving and load results? which makes it easier to resume the script the next time I need it?

It's easy to save text results, but in scipy, numpy, the result may be quite complex, e.g. matrix, numerical array.

Upvotes: 1

Views: 998

Answers (1)

Imanol Luengo
Imanol Luengo

Reputation: 15909

There are several options, such as 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 seem to be more appropiate.

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

Upvotes: 2

Related Questions