I have a couple of MongoDB documents wherein one my the fields is best represented as a matrix (numpy array). I would like to save this document to MongoDB, how do I do this?
{
'name' : 'subject1',
'image_name' : 'blah/foo.png',
'feature1' : np.array(...)
}
Have you try MongoWrapper, i think it simple :
Declare connection to mongodb server and collection to save your np.
The dictionary's just as you'd expect it to be:
Save data to mongo :
To load back data :
We've built an open source library for storing numeric data (Pandas, numpy, etc.) in MongoDB:
https://github.com/manahl/arctic
Best of all it's really easy to use, pretty fast and supports data versioning, multiple data libraries and more.
The code pymongo.binary.Binary(...) didnt work for me, may be we need to use bson as @tcaswell suggested.
Anyway here is one solution for multi-dimensional numpy array
Having said that, the credit goes to MongoWrapper used the code written by them.
Have you tried Monary?
They have examples on the site
http://djcinnovations.com/index.php/archives/103
For a 1D numpy array, you can use lists:
For multidimensional data, I believe you'll need to use pickle and pymongo.binary.Binary: