[Numpy-discussion] numpy.load raising IOError but EOFError expected
Keith Goodman
kwgoodman@gmail....
Mon Jun 28 16:05:28 CDT 2010
On Wed, Jun 23, 2010 at 3:46 AM, Ruben Salvador <rsalvador.wk@gmail.com> wrote:
> Hi there,
>
> I have a .npy file built by succesively adding results from different test
> runs of an algorithm. Each time it's run, I save a numpy.array using
> numpy.save as follows:
>
> fn = 'file.npy'
> f = open(fn, 'a+b')
> np.save(f, arr)
> f.close()
How about using h5py? It's not part of numpy but it gives you a
dictionary-like interface to your archive:
>> import h5py
>> io = h5py.File('/tmp/data.hdf5')
>> arr1 = np.array([1, 2, 3])
>> arr2 = np.array([4, 5, 6])
>> arr3 = np.array([7, 8, 9])
>> io['arr1'] = arr1
>> io['arr2'] = arr2
>> io['arr3'] = arr3
>> io.keys()
['arr1', 'arr2', 'arr3']
>> io['arr1'][:]
array([1, 2, 3])
You can also load part of an array (useful when the array is large):
>> io['arr1'][-1]
3
More information about the NumPy-Discussion
mailing list