最近在學習谷歌機器學習框架TensorFlow
遇到一個特徵工程的處理函數
調用第一次的時候打印結果是正確的,就是這句
selected_training_examples = select_and_transform_features(training_examples)
而執行這句
selected_validation_examples = select_and_transform_features(validation_examples)
死活不會執行print(r)
最後查了一下發現問題出在這一句:
LATITUDE_RANGES = zip(range(32, 44), range(33, 45))
python2的zip()函數返回的是一個列表,也就是說
LATITUDE_RANGES = zip(range(32, 44), range(33, 45))返回的是
[(32, 33), (33, 34), (34, 35), (35, 36), (36, 37), (37, 38), (38, 39), (39, 40), (40, 41), (41, 42), (42, 43), (43, 44)]
而我使用的是python3,zip函數返回的是一個元組對象
zip在python3中,處於優化內存的考慮,只能訪問一次
所以就出現了這個函數調用第2次不會去訪問LATITUDE_RANGES的現象。
解決方法:
把LATITUDE_RANGES = zip(range(32, 44), range(33, 45))換成
LATITUDE_RANGES = [(32, 33), (33, 34), (34, 35), (35, 36), (36, 37), (37, 38), (38, 39), (39, 40), (40, 41), (41, 42), (42, 43), (43, 44)]即可