Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store numpy array in mysql

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)

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)

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.

like image 531
iec2011007 Avatar asked Jun 08 '15 15:06

iec2011007


People also ask

How NumPy arrays are stored?

A NumPy array can be specified to be stored in row-major format, using the keyword argument order='C' , and the column-major format, using the keyword argument order='F' , when the array is created or reshaped. The default format is row-major.

Can I store objects in NumPy array?

NumPy arrays are typed arrays of fixed size. Python lists are heterogeneous and thus elements of a list may contain any object type, while NumPy arrays are homogenous and can contain object of only one type.

How do I save a NumPy file to CSV?

You can save your NumPy arrays to CSV files using the savetxt() function. This function takes a filename and array as arguments and saves the array into CSV format. You must also specify the delimiter; this is the character used to separate each variable in the file, most commonly a comma.

Can NumPy arrays run on GPU?

NumPy doesn't natively support GPU s. However, there are tools and libraries to run NumPy on GPU s. Numba is a Python compiler that can compile Python code to run on multicore CPUs and CUDA-enabled GPU s.


1 Answers

You could use ndarray.dumps() to pickle it to a string then write it to a BLOB field? Recover it using numpy.loads()

like image 177
paddyg Avatar answered Oct 21 '22 17:10

paddyg