Python lists are great, but they are too slow for the massive datasets used in Machine Learning. Enter NumPy.
NumPy (Numerical Python) is a library that allows us to do math at the speed of AI. The secret is the NumPy Array, which is like a Python list but heavily optimized for speed.
First, we always import the library, usually as np.
In standard Python, if you want to add 1 to every item in a list, you need a for loop. In NumPy, you can do it instantly with "vectorized" operations. This is the magic behind fast AI!
NumPy makes analyzing data a breeze with built-in functions:
np.mean(arr) - Averagenp.max(arr) - Maximum valuenp.std(arr) - Standard DeviationA very common preprocessing step in ML is standardizing features so they have a mean of 0. Let's do it with NumPy!
prices = np.array([100, 200, 300, 400, 500]).prices and store it in mean_price.std_price.normalized_prices by subtracting the mean from prices, and then dividing by the standard deviation. (Do it all in one vectorized line!).normalized_prices.