![](https://secure.gravatar.com/avatar/1bc8694bf55c688b2aa2075eedf9b4c6.jpg?s=120&d=mm&r=g)
I recently noticed that we can't pickle ufuncs (like sin, ...). Is there any technical reason this doesn't work, or is it in the category of 'just needs to be done...' FYI, I noticed that it didn't work on the old Numeric either. thanks, eric Python 2.4.3 - Enthought Edition 1.0.0 (#69, Aug 2 2006, 12:09:59) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
import pickle import numpy import math pickle.dumps(numpy.arange) 'cnumpy.core.multiarray\narange\np0\n.' pickle.dumps(math.sin) 'cmath\nsin\np0\n.' pickle.dumps(numpy.sin) Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\lib\pickle.py", line 1386, in dumps Pickler(file, protocol, bin).dump(obj) File "C:\Python24\lib\pickle.py", line 231, in dump self.save(obj) File "C:\Python24\lib\pickle.py", line 313, in save rv = reduce(self.proto) File "C:\Python24\lib\copy_reg.py", line 69, in _reduce_ex raise TypeError, "can't pickle %s objects" % base.__name__ TypeError: can't pickle ufunc objects
![](https://secure.gravatar.com/avatar/764323a14e554c97ab74177e0bce51d4.jpg?s=120&d=mm&r=g)
eric jones wrote:
I recently noticed that we can't pickle ufuncs (like sin, ...). Is there any technical reason this doesn't work, or is it in the category of 'just needs to be done...'
We talked about this about two weeks ago: http://projects.scipy.org/pipermail/numpy-discussion/2007-January/025778.htm... In short, there is a technical reason that it doesn't work in general, there is a workaround that will work for all of the ufuncs that are exposed in modules (but not those created on the fly by scipy.vectorize(), for example), and that workaround is in the category of "just needs to be done." -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (2)
-
eric jones
-
Robert Kern