神经网络与深度学习第一章问题(Python2.x转到python3.x)
今天看《Neural Networks and Deep Learning》的神经网络程序,源程序为python2.x,采用python3.6时会遇到一些错误:
转自http://blog.csdn.net/taotaoking/article/details/78583448
1、xrange ->range python3.6中已经没有xrange
2、在load minist数据库时会报错:
UnicodeDecodeError: 'ascii' codec can't decode byte
可改为如下:
with gzip.open('../data/mnist.pkl.gz', 'rb') as f:
training_data, validation_data, test_data = pickle.load(f,encoding='latin1')#特别注意后面的encoding='latin1'
3、import pickle 后面也改为pickle
4、SGD函数中zip出错,改为:
test_data=list(test_data)
n_test = len(test_data)# the number of testing samples
training_data = list(taining_data)
先转化为list然后再len
activation = self.sigmoid(z)
TypeError: sigmoid() takes 1 positional argument but 2 were given(其实包含了一个object参数隐藏)
应改为sigmoid(self,z),这样传入的默认object参数才能接收