Build the linear-algebra intuition used by machine-learning models and robotics.

Vectors, matrices, and dot products

Learning objectives

  • Represent a list of measurements as a vector.
  • Use a dot product to combine features and weights.
  • Interpret a matrix as a collection of vectors.
  • Connect geometric operations to model calculations.

A weighted score

Suppose a simple model uses practice minutes and completed projects:

import numpy as np

features = np.array([30, 2])
weights = np.array([0.1, 5])
bias = 2

score = features @ weights + bias
print(score)

The @ operator computes the dot product: multiply matching values and add the results. Here the score is 30 * 0.1 + 2 * 5 + 2 = 15.

Matrices

students = np.array([
    [30, 2],
    [12, 1],
    [45, 3],
])

scores = students @ weights + bias
print(scores)

Each row is one student and each column is one feature. The same weights are applied to every row. This is the basic shape of many model computations.

Practice

Change the weights and observe which feature affects the score more. Then explain why changing units, such as minutes to hours, requires changing the corresponding weight.

Checkpoint

What does one row represent? What does one column represent? Why must the number of weights match the number of features?

See the NumPy linear algebra documentation for array operations.