Pickle dump huge file without memory error

后端 未结 9 906
梦谈多话
梦谈多话 2020-12-23 14:26

I have a program where I basically adjust the probability of certain things happening based on what is already known. My file of data is already saved as a pickle

9条回答
  •  醉酒成梦
    2020-12-23 14:43

    None of the above answers worked for me. I ended up using Hickle which is a drop-in replacement for pickle based on HDF5. Instead of saving it to a pickle it's saving the data to HDF5 file. The API is identical for most use cases and it has some really cool features such as compression.

    pip install hickle
    

    Example:

    # Create a numpy array of data
    array_obj = np.ones(32768, dtype='float32')
    
    # Dump to file
    hkl.dump(array_obj, 'test.hkl', mode='w')
    
    # Load data
    array_hkl = hkl.load('test.hkl')
    

提交回复
热议问题