因为这本书是用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