Python 2 --> 3: object of type 'zip' has no len()

前端 未结 5 644
忘掉有多难
忘掉有多难 2020-12-13 17:38

I\'m following a tutorial on neural nets1

It\'s in Python 2.7. I\'m using 3.4. This is the line that troubles me:

if test_data: n_test = len(test_data)

5条回答
  •  醉酒成梦
    2020-12-13 17:56

    In mnist_loader wrap your zip results in list() constructs like below

    def load_data_wrapper():    
        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 = list(zip(training_inputs, training_results))
        validation_inputs = [np.reshape(x,(784, 1))for x in va_d[0]]
        validation_data = list(zip(validation_inputs, va_d[1]))
        test_inputs = [np.reshape(x, (784, 1)) for x in te_d[0]]
        test_data = list(zip(test_inputs, te_d[1]))
        return(training_data, validation_data, test_data)
    

提交回复
热议问题