我正在尝试在sqlite3数据库中存储大约1000个浮点数的numpy数组,但我不断收到错误"InterfaceError:Error binding parameter 1 - 可能不支持的类型".
我的印象是BLOB数据类型可能是任何东西,但它肯定不适用于numpy数组.这是我试过的:
import sqlite3 as sql
import numpy as np
con = sql.connect('test.bd',isolation_level=None)
cur = con.cursor()
cur.execute("CREATE TABLE foobar (id INTEGER PRIMARY KEY, array BLOB)")
cur.execute("INSERT INTO foobar VALUES (?,?)", (None,np.arange(0,500,0.5)))
con.commit()
Run Code Online (Sandbox Code Playgroud)
我可以使用另一个模块将numpy数组放入表中吗?或者我可以将numpy数组转换为Python中的另一种形式(如我可以拆分的列表或字符串),sqlite会接受吗?绩效不是优先事项.我只是想让它起作用!
谢谢!
我想从Python 3中的numpy数组中获取缓冲区.我找到了以下代码:
$ python3
Python 3.2.3 (default, Sep 25 2013, 18:25:56)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.arange(10)
>>> numpy.getbuffer(a)
Run Code Online (Sandbox Code Playgroud)
但是它会在最后一步产生错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getbuffer'
Run Code Online (Sandbox Code Playgroud)
我为什么做错了?该代码适用于Python 2.我使用的numpy版本是1.6.1.