Linear Algebra Basics

NumPy arrays double as vectors and matrices, and support the two operations most numerical code actually needs day to day: the dot product, and matrix multiplication.

The dot product

The dot product multiplies two equal-length vectors position by position, then adds up the results into a single number:

>>> np.dot and @ do the same thing
import numpy as np

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(np.dot(a, b))
print(a @ b)
Output
32
32

1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32. np.dot(a, b) and the @ operator compute exactly the same thing — @ is just a shorter, more common way to write it in modern NumPy code.

Matrix multiplication

The same @ operator extends naturally to full matrix multiplication for 2D arrays:

>>> multiplying two 2x2 matrices
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
print(A @ B)
Output
[[19 22]
 [43 50]]

Each entry in the result is the dot product of a row from A and a column from B — for example, the top-left 19 comes from (1*5) + (2*7).

Note: A * B (plain multiplication) is not matrix multiplication — it multiplies matching positions element by element, the same broadcasting behavior from the Array Operations lesson. This is one of the most common NumPy mistakes for anyone coming from a math background expecting * to mean matrix multiplication. Always use @ or np.matmul() when you actually want matrix multiplication.
Course complete: that covers the NumPy course from top to bottom — creating arrays several different ways, indexing and slicing in one and two dimensions, element-wise operations and broadcasting, reshaping data without copying it, axis-based aggregations, boolean filtering, and the dot product and matrix multiplication that make NumPy the foundation for pandas, scikit-learn, and most of the numerical Python ecosystem.