numpy 資料型別存入資料庫中

2021-08-28 20:49:30 字數 698 閱讀 6278

import numpy as np

import pymysql

prediction = np.array()

mysql_server='localhost'

name='root'

password='your password'

mysql_db='your database'

db=pymysql.connect(mysql_server,name,password,mysql_db)

x = np.array([0,0,0,0,1,0,0,0 ,0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1])

# print(type(x)) #這裡是ndarray的型別

for item in x.flat:

item

cursor=db.cursor()

cursor.execute("insert into db (column) values(%s)",int(item))

db.commit()

有很多人不知道numpy的資料型別怎麼存入資料庫,就拿上面的來說

上面輸出的型別結果是ndarray,用乙個迴圈  資料用.flat就可以迴圈出來。當插入資料庫的時候,陣列是int32  ,資料庫欄位的屬性設定為int型別 長度11就可以插入了。

資料庫中資料型別

1.整型 整型選取原則 第一 要滿足欄位的表示範圍 第二 盡量選擇占用空間小的資料型別 第三 如果不儲存負數,盡量新增unsigned屬性 2.浮點型 整型選取原則 第一 要滿足欄位的表示範圍 第二 盡量選擇占用空間小的資料型別 第三 能選取整型的不選取float型。3.字元型 char和varch...

NumPy 資料型別

numpy 支援比 python 更多種類的數值型別。下表顯示了 numpy 中定義的不同標量資料型別。序號資料型別及描述 1.bool 儲存為乙個位元組的布林值 真或假 2.int 預設整數,相當於 c 的long,通常為int32或int64 3.intc相當於 c 的int,通常為int32或...

NumPy 資料型別

numpy提供的數值型別,數值範圍比python提供的數值型別更大。numpy的數值型別,如下表所示 sn資料型別描述1 bool 布林值,取值ture false,占用乙個位元組 2int 是integer的預設型別。與c語言中的long型別相同,有可能是64位或32位。3intc 類似於c語言中...