NumPy Fundamentals
60 min
NumPy
40%
Why NumPy for Machine Learning?
NumPy is the foundation of scientific computing in Python. Almost every ML library (TensorFlow, PyTorch, Scikit-learn) is built on top of NumPy.
Key Benefits
1. Speed: NumPy operations are implemented in C, making them 10-100x faster than pure Python 2. Memory Efficiency: Homogeneous arrays use less memory than Python lists 3. Broadcasting: Perform operations on arrays of different shapes 4. Linear Algebra: Built-in functions for matrix operations
Installation
pip install numpy
Basic Import Convention
import numpy as npCreate your first array
arr = np.array([1, 2, 3, 4, 5])
print(arr) [1 2 3 4 5]
print(type(arr))
NumPy vs Python Lists
import timePython list operation
python_list = list(range(1000000))
start = time.time()
result = [x * 2 for x in python_list]
print(f"Python list: {time.time() - start:.4f}s")NumPy array operation
numpy_array = np.arange(1000000)
start = time.time()
result = numpy_array * 2
print(f"NumPy array: {time.time() - start:.4f}s")
NumPy is typically 50-100x faster!