lundi 20 juillet 2015

related to Python insert numpy array into sqlite3 database http://ift.tt/1n7Atny

`def adaptArray(self, arr): out = io.BytesIO() numpy.save(out, arr) out.seek(0) return sqlite3.Binary(out.read())

def convert_array(self, text):
    out = io.BytesIO(text)
    out.seek(0)
    return numpy.load(out)

def SaveToDatabase(self):
    #try:
        connection = sqlite3.connect('efit.db')
        cursor = connection.cursor()
        cursor.execute("DROP TABLE IF EXISTS MlamMmueMrhoMdam")
        cursor.execute("CREATE TABLE MlamMmueMrhoMdam(x INT, y INT,  Mlam BLOB, Mmue BLOB, Mrho BLOB, Mdam BLOB)")
        cursor.execute("INSERT INTO MlamMmueMrhoMdam( x, y, Mlam, Mmue, Mrho, Mdam) VALUES(?,?,?,?,?,?)", ( len(self.Mlam), 
                                                                                                            len(self.Mlam[0]),
                                                                                                            sqlite3.register_adapter(self.Mlam, self.adaptArray(self.Mlam )), 
                                                                                                            sqlite3.register_adapter( self.Mmue, self.adaptArray(self.Mmue) ), 
                                                                                                            sqlite3.register_adapter(self.Mrho, self.adaptArray(self.Mrho) ) , 
                                                                                                            sqlite3.register_adapter( self.Mdam, self.adaptArray(self.Mdam) )  ))
        connection.commit()
    #except Exception as e:
        #print e
    #finally:
        connection.close()`

I get sqlite3.register_adapter(self.Mlam, self.adaptArray(self.Mlam )), TypeError: unhashable type: 'numpy.ndarray'

I tried to make the 2D array it hashable (http://ift.tt/1JbrgU5) ... it does not work sisnce it does not return an Array, and if I return it, it's again unhashable

Can someone cut the forest down from before my eyes? Help...

Aucun commentaire:

Enregistrer un commentaire