What’s the most efficient way to convert a MySQL result set to a NumPy array?

This solution uses Kieth’s fromiter technique, but handles the two dimensional table structure of SQL results more intuitively. Also, it improves on Doug’s method by avoiding all the reshaping and flattening in python data types. Using a structured array we can read pretty much directly from the MySQL result into numpy, cutting out python data … Read more

NumPy append vs Python append

OP intended to start with empty array. So, here’s one approach using NumPy In [2]: a = np.empty((0,3), int) In [3]: a Out[3]: array([], shape=(0L, 3L), dtype=int32) In [4]: a = np.append(a, [[1,2,3]], axis=0) In [5]: a Out[5]: array([[1, 2, 3]]) In [6]: a = np.append(a, [[1,2,3]], axis=0) In [7]: a Out[7]: array([[1, 2, 3], … Read more