Exporting data from sqlite to numpy array

前端 未结 1 1424
庸人自扰
庸人自扰 2021-01-06 07:40

I\'m not a programmer, I do this purely as a hobby..

I found a way to save numpy array in to sqlite database

import sqlite3
import numpy

# Array of          


        
相关标签:
1条回答
  • 2021-01-06 08:43

    Just fetch all the values. That gives you a list of tuples. np.array() takes you back to the original array:

    In [12]: cursor.execute('SELECT * from data')
    Out[12]: <sqlite3.Cursor at 0xaf8e9d60>
    In [13]: alist = cursor.fetchall()
    In [14]: len(alist)
    Out[14]: 100
    In [15]: alist[0]
    Out[15]: 
    (0.3327498114993416,
     0.6164620040846208,
     0.5099007559772143,
     0.7808234554641948)
    In [16]: data1 = np.array(alist)
    In [17]: np.allclose(data, data1)
    Out[17]: True
    

    The fact that it's a list of tuples doesn't matter. It's just as good as a list of lists.

    0 讨论(0)
提交回复
热议问题