在MySQL中存储numpy数组 [英] store numpy array in mysql
问题描述
我的用例很简单,我对图像执行了某种操作,结果特征向量是形状为rowX1000的numpy对象(我的意思是说行号可以是可变的,但列号始终是1000 )
My use case is simple, i have performed some kind of operation on image and the resulting feature vector is a numpy object of shape rowX1000(what i mean to say is that the row number can be variable but column number is always 1000)
我想将此numpy数组存储在mysql中.对此数组不执行任何类型的操作.给定图像名称返回整个特征向量,查询将很简单.因此,有什么方法可以存储数组(就像魔术容器一样,该容器封装了该数组,然后将其放在桌子上,并在检索时检索魔术容器并弹出该数组)
I want to store this numpy array in mysql. No kind of operation is to be performed on this array. The query will be simple given a image name return the whole feature vector. so is there any way in which the array can be stored (something like a magic container which encapsulates the array and then put it on the table and on retrieval it retrieves the magic container and pops out the array)
我想用python做到这一点.如果可能,请使用简短的代码片段支持如何将数据放入mysql数据库.
I want to do this in python. If possible support with a short code snippit of how to put the data in the mysql database.
推荐答案
您可以使用ndarray.dumps()将其腌制为字符串,然后将其写入BLOB字段?使用numpy.loads()恢复它
You could use ndarray.dumps() to pickle it to a string then write it to a BLOB field? Recover it using numpy.loads()
这篇关于在MySQL中存储numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!