I understand that generators in python atleast are memeory efficent as it deals with one item at a time but how does this make it time efficent (if it is) ?
Specifically, say I'm using generator function to load one data at a time for a machine learning task. At the end of the day, I will still need to loop over all the data elements and load them one at a time( using generator function). Yes, this is memeory efficent but this should instead take a lot more time to load the entire dataset than say loading all at once. Is my intuition right ?
#sample_code
def my_gen():
for i in range(1000):
features = np.random.randn(32,32,3)
labels = np.random.randint(0,1, size = 1)
yield features, labels