TypeError: object of type 'zip' has no len()、'zip' object is not subscriptable

TypeError: object of type ‘zip’ has no len()、‘zip’ object is not subscriptable
zip 对象没有length属性不可以遍历

代码报错:

print(len(training_data)) # TypeError: object of type 'zip' has no len()
print(training_data[0][0].shape) # TypeError: 'zip' object is not subscriptable

源代码部分代码:

    test_data = zip(test_inputs, te_d[1])
    return (training_data, validation_data, test_data)

解决方法:zip对象用list包装即可

    test_data = list(zip(test_inputs, te_d[1]))
    return (training_data, validation_data, test_data)

你可能感兴趣的:(TypeError: object of type 'zip' has no len()、'zip' object is not subscriptable)