[Numpy-discussion] xml-rpc with numpy arrays

Lisandro Dalcin dalcinl@gmail....
Tue Sep 30 17:24:56 CDT 2008


Sebastien, numpy arrays are picklable; so no need to register them
with copy_reg. I believe the actual problem with xmlrpclib is that it
uses the marshal protocol (only supports core builtin types), and not
the pickle protocol.

On Tue, Sep 30, 2008 at 5:18 PM, Sebastien Binet
<hep.sebastien.binet@gmail.com> wrote:
> Hi,
>
> [..snip..]
> On Tuesday 30 September 2008 12:05:27 Robert Kern wrote:
>> > doing something wrong.  Is there a way to fix this?  Is there another
>> > approach that I should be using?
>>
>> The marshal module *only* handles builtin Python types. It explicitly
>> does not handle anything from third parties like numpy.
>
> but you can use the copy_reg module ('copyreg' in py2.6) to register
> pickling/unpickling functions to make 'pickle' able to handle user-types:
>
> ## test_pickling_numpy.py ##
> import numpy
> import copy_reg
> import cPickle as pickle
>
> def from_string(s):
>    return numpy.fromstring(s)
>
> def to_string(o):
>    return from_string, (o.tostring(),)
>
> a = numpy.arange (10,dtype=float)
> copy_reg.pickle (numpy.ndarray, to_string, from_string)
> s = pickle.dumps (a)
> b = pickle.loads (s)
> assert (a==b, "pickling failed !")
> ## EOF ##
>
> see for more informations:
> http://effbot.org/librarybook/copy-reg.htm
>
> cheers,
> sebastien.
> --
> ###################################
> # Dr. Sebastien Binet
> # Lawrence Berkeley National Lab.
> # 1 Cyclotron Road
> # Berkeley, CA 94720
> ###################################
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594


More information about the Numpy-discussion mailing list