Learn Before
Concept
Python Generator
A Python generator is a special type of function that returns a lazy iterator. Instead of computing and storing all values in memory at once, a generator produces one value at a time using the yield keyword, pausing its execution state between calls. This memory-efficient approach makes generators highly effective for processing large datasets, such as in deep learning data loaders where they iteratively yield a single data batch without loading the entire dataset into memory.
0
1
Updated 2026-05-02
Tags
D2L
Dive into Deep Learning @ D2L