使用**tolist()**完成數組轉換,使用astype 能夠指定數據類型
from numpy import *
#tolist astype
a = array([1,2,3,4,5,6])
print(a)
print(a.tolist()) #將numpy中的數組轉換爲python中的列表
print("-----------------------1111--------------------------")
b = a.reshape(2,3)
print(b)
print(b.tolist())
print("-----------------------2222--------------------------")
a = array([1,2,3,4,5,'6'])
print(a.astype(int)) #astype 能夠指定數據類型
print("-----------------------3333--------------------------")
a = array([1,2,3,4,5,'x'])
#print(a.astype(int)) #因爲數組a中有字符串x,不能轉換爲int型,所以會拋出異常
參考鏈接:
https://blog.csdn.net/zhubao124/article/details/80719306