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

前端 未结 5 640
忘掉有多难
忘掉有多难 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 18:12

    A bit late now to answer, but in case anyone else stumbles on it: for that same neural net example tutorial, it turned out I had to wrap the 3 zip calls in the mnist_loader with a list(zip(...)) construct:

    training_data = list(zip(training_inputs, training_results))
    (...)
    validation_data = list(zip(validation_inputs, va_d[1]))
    (...)
    test_data = list(zip(test_inputs, te_d[1]))
    

    And then it worked.

提交回复
热议问题