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. A matrix–vector product applies each row to the same input
  3. With input (3,1), row (1,2) gives 5
  4. Every row needs one input per column
  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

01A matrix–vector product applies each row to the same input#

A matrix–vector product applies each row to the same input. For rows (1,2)(1,2) and (0,1)(0,-1) with input (3,1)(3,1), two dot products produce two output entries.

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

Take the first row (1,2)(1,2) and input (3,1)(3,1). Multiply matching positions, then add. This result becomes the first output entry.

13+21=51\cdot3+2\cdot1=5
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.

02With input (3,1), row (1,2) gives 5#

With input (3,1)(3,1), row (1,2)(1,2) gives 5. Row (0,1)(0,-1) gives 03+(1)1=10\cdot3+(-1)\cdot1=-1. Place those results in row order:

Ax=[51]Ax=\begin{bmatrix}5\\-1\end{bmatrix}
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.

03Every row needs one input per column#

Every row needs one input per column. A matrix with three rows and two columns takes a two-entry input and returns three entries. A missing input makes the row dot products undefined.

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 41=34-1=3.

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]

Reference this concept

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

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