哪种数据类型最适合在PostgreSQL中存储ndarray

时间:2019-04-08 07:05:11

标签: postgresql python-2.7 face-recognition

我是python的新手。我正在尝试将编码的面部识别数据存储到具有numpy.ndarray类型的postgresql .data。如何将其存储到数据库

我已经在postgresql中创建了数据类型为float的表来存储这种数据。 [-0.18851721 0.1335005 0.05511604 -0.06277356 -0.02851189 0.05052128  -0.07445884 -0.13722856 0.1954176 -0.06740481 0.25077775 0.10245039  -0.18124828 -0.16744739 -0.00625956 0.12364798 -0.16207671 -0.1176396  -0.1011513 -0.10095926 0.03207059 0.04325461 0.09359518 0.02856386  -0.13979232 -0.36666855 -0.07963274 -0.17080374 -0.02638249 -0.1269975  -0.0090007 0.02657734 -0.20248355 -0.09234729 0.02776779 0.02405531   0.00760813 0.00992479 0.19022804 0.06206769 -0.09040014 0.05418085   0.064793 0.22478105 0.25524226 0.06918503 -0.02772347 -0.06143937   0.11962473 -0.21881692 0.06122055 0.16483036 0.06817284 0.05840653   0.13647863 -0.15373509 0.02558955 0.07045594 -0.14521058 0.03485384  -0.00699617 -0.09832785 -0.09840143 0.03895607 0.15690036 0.10940056  -0.09321431 -0.10966937 0.13620195 -0.00220358 -0.03094646 0.05223915  -0.17761797 -0.18311672 -0.21710058 0.09066689 0.38883513 0.1444997  -0.23706336 0.01360968 -0.16185056 -0.01500403 0.00909736 -0.00461302  -0.04799315 -0.12826051 -0.05354946 0.00862529 0.09347358 0.08640108  -0.03517354 0.24804059 -0.02498217 0.03270505 0.03874825 0.06522777  -0.1336177 -0.01356841 -0.16400115 -0.10731176 0.03216686 -0.01949028  -0.00452124 0.08888718 -0.23588364 0.11363064 0.01547772 -0.03120285  -0.01432095 -0.00138823 -0.07527658 0.03971821 0.10038127 -0.25322253   0.28212106 0.21040824 0.00970344 0.17483208 0.10048124 0.01512941  -0.00569613 -0.01414334 -0.12674388 -0.12199711 0.0511818 0.00163262   0.02390176 0.00650601]

import face_recognition
import psycopg2
import numpy

con = psycopg2.connect(user="postgres", password="root", 
host="127.0.0.1", port="5432",database="testdb")
con.autocommit = True
print("Database opened successfully")
cur = con.cursor()
known_image = 
face_recognition.load_image_file("/home/cygnet/Pictures/o1.jpeg")
biden_encoding = (face_recognition.face_encodings(known_image)[0])
arr=numpy.array(biden_encoding,numpy.float128)
print(arr)
cur.execute("insert into img2(id,img) values(%s,%s)",(1,arr))

它给我和类似的错误 psycopg2.ProgrammingError:无法适应类型'numpy.ndarray' 请指导我在PostgreSQL中需要哪种数据类型来存储numpy.ndarray或如何在PostgreSQL中存储该数据。

0 个答案:

没有答案
相关问题