3
Linear Algebra in Practice
Now that we understand the geometric structure of vector spaces, it’s time to put the theory into practice once again. In this chapter, we’ll take a hands-on look at norms, inner products, and NumPy array operations in general. Most importantly, we’ll also meet matrices for the first time.
The last time we translated theory to code, we left off at finding an ideal representation for vectors: NumPy arrays. NumPy is built for linear algebra and handles computations much faster than the vanilla Python objects.
So, let’s initialize two NumPy arrays to play around with!
import numpy as np
x = np.array([1.8, -4.5, 9.2, 7.3])
y = np.array([-5.2, -1.1, 0.7, 5.1])
In linear algebra, and in most of machine learning, almost all operations involve looping through the vector components one by one. For instance, addition can be implemented like this.
def add(x: np.ndarray, y: np.ndarray):
x_plus_y = np.zeros(shape=len(x)...