mongodb如何存numpy数组
Ly
2020-06-09 15:44:114458浏览 · 0收藏 · 0评论
1、对于一维numpy数组,可以使用列表:
# serialize 1D array x record['feature1'] = x.tolist() # deserialize 1D array x x = np.fromiter( record['feature1'] )
2、对于多维数组,你需要使用pickle和pymongo.binary.Binary:
# serialize 2D array y record['feature2'] = pymongo.binary.Binary( pickle.dumps( y, protocol=2) ) ) # deserialize 2D array y y = pickle.loads( record['feature2'] )
关注公众号,随时随地在线学习