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.
http://combichem.blogspot.dk/2013/02/saving-into-data-into-cpickle-format-in.html

I have also been using Numpy's save function to do the same thing. numpy.save() and numpy.load() is so much simpler, however. I really recommend that people use numpy.save() 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!

Source: http://stackoverflow.com/questions/16833124/pickle-faster-than-cpickle-with-numeric-data








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

  numpy.save("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.

    ReplyDelete