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
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)