因爲這本書是用python2寫的有些地方和python有一點不一樣,因而報錯的地方或是其他一些小問題,記錄下來。一直更新。
1. UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence
不能解碼gbk的內容,修改如下:
file= open(‘order.log’,‘rb’)
類似問題
TypeError: write() argument must be str, not bytes
open(‘文件路徑’,‘wb’)
2.RuntimeWarning: Glyph missing from current font. font.set_text(s, 0, flags=flags)
找不到字體
plt.rcParams[‘font.sans-serif’]=[‘SimHei’] #顯示中文標籤
3.’range’ object doesn’t support item deletion
該句代碼爲del(trainingSet[randIndex])
把前面的 trainingSet = range(50) 轉化爲 trainingSet = list(range(50))因爲python在range返回的是range對象,不是數組
4.TypeError: unsupported operand type(s) for /: ‘map’ and ‘int’
5.TypeError: unhashable type: ‘matrix’
5.AttributeError: type object ‘Tk’ has no attribute ‘tk’
import tkinter(小寫)
6.AttributeError: ‘FigureCanvasTkAgg’ object has no attribute ‘show’
7.ValueError: Masked arrays must be 1-D
8.TypeError: unsupported operand type(s) for -: ‘map’ and ‘map’
9. AttributeError: ‘dict’ object has no attribute ‘hash_key’
10.TypeError: object of type ‘map’ has no len()
11. datArr = [list(map(float, line)) for line in stringArr]第13章pca