[Numpy-discussion] patch to pickle np.memmap

Brent Pedersen bpederse at gmail.com
Mon Apr 19 13:39:59 EDT 2010


On Tue, Apr 13, 2010 at 8:59 PM, Brent Pedersen <bpederse at gmail.com> wrote:
> On Tue, Apr 13, 2010 at 8:52 PM, Brent Pedersen <bpederse at gmail.com> wrote:
>> hi, i posted a patch to allow pickling of np.memmap objects.
>> http://projects.scipy.org/numpy/ticket/1452
>>
>> currently, it always returns 'r' for the mode.
>> is that the best thing to do there?
>> any other changes?
>> -brent
>>
>
> and i guess it should (but does not with that patch) correctly handle:
>
>>>> a = np.memmap(...)
>>>> b = a[2:]
>>>> cPickle.dumps(b)
>

any thoughts? it still always loads in mode='r', but
i updated the patch to handle slicing so it works like this:

>>> import numpy as np
>>> a = np.memmap('t.bin', mode='w+', shape=(10,))
>>> a[:] = np.arange(10)
>>> a
memmap([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint8)
>>> np.loads(a[1:4].dumps())
memmap([1, 2, 3], dtype=uint8)
>>> np.loads(a[-2:].dumps())
memmap([8, 9], dtype=uint8)
>>> np.loads(a[-4:-1].dumps())
memmap([6, 7, 8], dtype=uint8)

http://projects.scipy.org/numpy/ticket/1452

-brent



More information about the NumPy-Discussion mailing list