![loop memory monitor loop memory monitor](https://prizes.poq.gg/wp-content/uploads/2019/12/81KNq8dVBbL.jpg)
> import sys > my_generator_list = (i*2 for i in range(100000)) > print(f"My generator is bytes") My list is 824472 bytes > timeit(my_list) 10000000 loops, best of 5: 34.5 ns per loop
![loop memory monitor loop memory monitor](https://techreport.com/r.x/2016_3_3_EK_Water_Blocks_releases_Professional_Series_CPU_kit/pkit280poster_1.jpg)
Hence, Yield is suitable for large datasets, or when you don’t need to store all the output values but just one value for each iteration of the main function. > def say_hello(): > yield "HELLO!" > SENTENCE = say_hello() > print(next(SENTENCE)) HELLO! > print("calling the generator again: ", list(SENTENCE)) calling the generator again: Īs there is no value returned unless the generator object is iterated, no memory is used when the Yield function is defined, while calling Return in a function leads to the allocation in memory. If you access it the second time, it returns empty. However, generators are for one-time use objects. > def say_hello(): > yield "HELLO!" > SENTENCE = say_hello() > print(next(SENTENCE)) HELLO! To read the generator’s values, you can use list(), for loop, or next(). To get the values of the object, it has to be iterated to read the values given to the yield. Python yield returns a generator object, which converts the expression given into a generator function. To check type minimum and maximum values, you can use function numpy.iinfo(), and numpy.finfo() for float.īelow is the summary information for each type. Depending on different needs and objectives, using sufficient data types becomes vital know-how. I narrow them down to uint, int, and float given these are the most common when training models, handling data in Python. In Numpy, there are multiple types, including boolean (bool), integer (int), Unsigned integer (uint), float, complex, datetime64, timedelta64, object_, etc... # Check numpy integer > import numpy as np > ii16 = np.iinfo(np.int16) > ii16 iinfo(min=-32768, max=32767, dtype=int16) # Access min value > ii16.min -32768 Optimized data typeīy understanding how data is stored and manipulated and using the optimal data type for the tasks, it will save you huge space in memory and computation time. However, if you want to train a Machine Learning model on tabular data without using Deep learning (hence, not using Pytorch) or you don’t have access to a Database and have to work solely on the memory, what will be the choice for memory optimization? 2.