Write numpy arrays to lmdb

前端 未结 1 1929
遥遥无期
遥遥无期 2021-01-22 05:00

I\'m trying to write some numpy arrays in python to lmdb:

import numpy as np
import lmdb

def write_lmdb(filename):
    lmdb_env = lmdb.open(filename, map_size=i         


        
相关标签:
1条回答
  • 2021-01-22 05:45

    Wrap your transactions under with. And remember to convert the value from bytes (string) back to numpy array using np.fromstring.

    To be honest, it is not a good idea to store numpy array in lmdb since conversion from array to bytes back to array will lose some informations (ex. shape). You can try storing a dict of numpy arrays using pickle.

    def write_lmdb(filename):
        ...
        with lmdb_env.begin(write=True) as lmdb_txn:
            ...
    
    def read_lmdb(filename):
        ...
        with lmdb_env.begin() as lmdb_txn:
            with lmdb_txn.cursor() as lmdb_cursor:
                ...
                print np.fromstring(value, dtype=np.float64)
    
    0 讨论(0)
提交回复
热议问题