私はPythonでwhileループについて質問をします。 コードがループに断線がないwhileループを停止する方法は?
def batched(iterator, batch_size):
while True:
data = np.zeros(batch_size)
target = np.zeros(batch_size)
for index in range(batch_size):
data[index], target[index] = next(iterator)
yield data, target
batches = batched(examples, params.batch_size)
for index, batch in enumerate(batches):
.......
.......
下にあり、それは永遠に真続けるので、このループはどのように停止することができます。 ps。このコードは、TensorFlow for Machine Intelligenceの本の例です。
'batched'はイテレータです。 'yield'は、イテレータが次に呼び出されるまでループを一時停止します。したがって、反復( 'for'ループ)が終了条件を持っていれば、良いことです! Pythonで 'iterators'を読んでみると、いくつかのことがクリアされるはずです。 – Harsh