Skip to content
Glacius
Linear algebraConcept reference

Matrix-vector products

A matrix–vector product dots every matrix row with the input vector, producing one output entry per row.

On this page 7 sections
  1. Overview
  2. Several row scores
  3. Dimensions describe the operation
  4. Rows can describe observations
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections
Matrix-vector product: rows (1,2) and (0,−1) act on input (3,1), producing (5,−1). The highlighted first row corresponds to the first output. Layout is schematic.Matrix-vector product: rows (1,2) and (0,−1) act on input (3,1), producing (5,−1). The highlighted first row corresponds to the first output. Layout is schematic.
Figure 1Matrix-vector product: rows (1,2) and (0,−1) act on input (3,1), producing (5,−1). The highlighted first row corresponds to the first output. Layout is schematic.
Link to this figure ↗Download SVGDownload PNG

01Several row scores#

A matrix-vector product evaluates several dot products with the same input. Each row contains one set of weights. Its result becomes one entry of the output vector, in row order.

Let AA have rows (1,2)(1,2) and (0,−1)(0,-1), with input x=(3,1)x=(3,1). The first row asks for 1(3)+2(1)=51(3)+2(1)=5. The second asks for 0(3)−1(1)=−10(3)-1(1)=-1.

(120−1)(31)=(5−1)\begin{gathered}\begin{pmatrix}1&2\\0&-1\end{pmatrix}\begin{pmatrix}3\\1\end{pmatrix}\\=\begin{pmatrix}5\\-1\end{pmatrix}\end{gathered}

There are two output values because there are two rows. Both rows use the entire input. Assigning the first input entry to the first row and the second entry to the second row would omit terms from both dot products.

Check your reasoning

A has rows (2,1)(2,1) and (−1,0)(-1,0). Input is (1,3)(1,3). Compute AxAx.

  1. A(5,−1)
  2. B(−1,5)
  3. C(5)
Show answer and explanation
(5,−1)

Row 1 gives 2+3=52+3=5; row 2 gives −1-1.

02Dimensions describe the operation#

An m×dm\times d matrix has mm rows, each with dd weights. Its input needs dd entries so every weight has a partner. It returns mm entries, one per row.

A⏟m×dx⏟d×1=Ax⏟m×1\underbrace{A}_{m\times d}\underbrace{x}_{d\times1}=\underbrace{Ax}_{m\times1}
Check your reasoning

A matrix has 4 rows and 2 columns. The input has 2 entries. How many output entries?

  1. A2
  2. B4
  3. C6
Show answer and explanation
4

One dot product per row gives four entries.

For rows (1,0)(1,0), (0,1)(0,1), and (1,−1)(1,-1) with input (4,2)(4,2), the outputs are 44, 22, and 22. The last row compares the input coordinates. A rectangular matrix can produce more or fewer coordinates than it receives.

03Rows can describe observations#

A data matrix can put one observation in each row. If the rows are (1,2)(1,2), (2,0)(2,0), and (0,1)(0,1) and shared weights are (2,1)(2,1), the three scores are 44, 44, and 11.

This uses exactly the same row rule. The matrix's interpretation tells you whether outputs label observations or different scoring rules; the dimensions alone do not assign those meanings.

Check your reasoning

Input (2,1)(2,1). P weights (1,3)(1,3); Q weights (2,−1)(2,-1). Dot each with the input. Return (P, Q).

  1. A(3,5)
  2. B(5,5)
  3. C(5,3)
Show answer and explanation
(5,3)

P is 2+3=52+3=5; Q is 4−1=34-1=3.

Changing just one row changes only its output score. Changing an input coordinate can affect every row whose corresponding weight is nonzero. These are direct consequences of evaluating each row separately.

Key takeaway

Dot each row with the whole input. Keep the results in row order.

  • Compute a matrix-vector product from row dot products.

Sources & further reading

  1. [1]
  2. [2]
  3. [3]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Matrix-vector products.” Math behind ML. /learn/la-matvec