Course contentsShow
Machine Learning and Deep Learning
Lesson 5 of 3,5381. Mathematical Foundations for Machine LearningFree lesson

Matrix-Vector Multiplication

Master multiplying matrices by vectors: mechanics, dimensions, and interpretation as linear transformations.

Matrix-Vector Multiplication

What you'll learn: How to multiply a matrix by a vector to transform data—a fundamental operation underlying predictions in machine learning.

What Is Matrix-Vector Multiplication?

When you multiply a matrix by a vector, you're applying a linear transformation—essentially reshaping or rotating your data in space. Each row of the matrix performs a dot product with the vector, producing one number in the output vector.

Think of it like a recipe card system: each recipe (matrix row) takes your ingredients (input vector) and combines them with specific weights to create one dish (output element).

The Mechanics

Given a matrix A with dimensions m × n and a vector x with n elements:

  1. Check dimensions: The number of columns in A must equal the length of x
  2. Compute each output element: The i-th element of the result equals the dot product of the i-th row of A with x
  3. Result shape: You get an output vector with m elements

Example

Matrix A (2×3):

[2  1  3]
[0  4  1]

Vector x (3 elements):

[1]
[2]
[3]

Result (2 elements):

  • First element: (2×1) + (1×2) + (3×3) = 2 + 2 + 9 = 13
  • Second element: (0×1) + (4×2) + (1×3) = 0 + 8 + 3 = 11

Output: [13, 11]

Why It Matters

Every neuron in a neural network performs matrix-vector multiplication! Your input features (vector) get combined using learned weights (matrix rows) to produce predictions. This operation transforms raw data into meaningful outputs.

Key Takeaway: Matrix-vector multiplication applies a linear transformation by taking dot products of each matrix row with the input vector—the dimensions must align (matrix columns = vector length), and the output vector has as many elements as the matrix has rows.