[Numpy-discussion] Fastest way to save a dictionary of numpy record arrays
Mon Jun 14 19:30:45 CDT 2010
On Mon, Jun 14, 2010 at 19:27, Warren Weckesser
> Robert Kern wrote:
>> On Mon, Jun 14, 2010 at 19:00, Vishal Rana <email@example.com> wrote:
>>> I have dictionary of numpy record arrays, what could be fastest way to
>>> save/load to/from a disk. I tried numpy.save() but my dictionary is lost and
>>> cPickle seems to be slow.
>> numpy.savez() will save a dictionary of arrays out to a .zip file.
>> Each key/value pair will map to a file in the .zip file with a file
>> name corresponding to the key.
> Hey Robert,
> If I expand the dictionary to keyword arguments to savez, it works
> In : a = np.array([[1,2,3],[4,5,6]])
> In : b = np.array([('foo',1),('bar',2)], dtype=[('name', 'S8'),
> ('code', int)])
> In : d = dict(a=a, b=b)
> In : np.savez('mydata.npz', **d)
> In : q = np.load('mydata.npz')
> In : q['a']
> array([[1, 2, 3],
> [4, 5, 6]])
> In : q['b']
> array([('foo', 1), ('bar', 2)],
> dtype=[('name', '|S8'), ('code', '<i4')])
> But if I just pass in the dictionary to savez:
"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
More information about the NumPy-Discussion