Friday, August 16, 2013

Numpy vs. cPickles (Python, ofc)

I've been using cPickels for storing data into a Python-friendly format for some time. See my earlier blog post for more on cPickles.

I have also been using Numpy's save function to do the same thing. and numpy.load() is so much simpler, however. I really recommend that people use and numpy.load() over cPickles for most purposes. It is so much more simple.

I always thought a cPickle was much, much faster than Numpy, but I guess I was wrong, according to this stackoverflow I just saw. Below are loading and saving times for a large array. Practically no difference between Numpy and cPickles!


To save an array, a list or dictionary or whatever called my_array into my_file.npy:"my_file", my_array)

Note that Numpy appends .npy to the filename automatically.

To load the stored data simply:

  my_array = numpy.load("my_file.npy")

 Really py-fragging-thonicly easy!

1 comment:

  1. It has been a real frightening difficulty in my position, but witnessing a expert style you dealt with that took me to weep for happiness. Check shabbat candles for best candles.