python bug(六)——TypeError: object of type ‘zip’ has no len()
在python3上跑Neural Networks and Deep Learning的手写数字识别代码时,神经网络部分的代码出现了这个bug:
if test_data: n_test = len(test_data)
TypeError: object of type ‘zip’ has no len()
这应该是版本变更带来的问题,将程序里的
if test_data: n_test = len(test_data)
改为
if test_data: n_test = list(len(test_data))
还有读取数据部分
tr_d, va_d, te_d = load_data()
training_inputs = [np.reshape(x, (784, 1)) for x in tr_d[0]]
training_results = [vectorized_result(y) for y in tr_d[1]]
training_data = zip(training_inputs, training_results)
validation_inputs = [np.reshape(x, (784, 1)) for x in va_d[0]]
validation_data = zip(validation_inputs, va_d[1])
test_inputs = [np.reshape(x, (784, 1)) for x in te_d[0]]
test_data = zip(test_inputs, te_d[1])
return (training_data, validation_data, test_data)
改为:
问题解决!
参考资料:
https://blog.csdn.net/qq_17105473/article/details/72823462
https://blog.csdn.net/qq_41185868/article/details/79039704
还没有评论,来说两句吧...