Discord

INAIO Guide Stage 1 11Matrices and Linear Transformations

11.3 Matrix–vector multiplication

Multiply each matrix row by a vector to compute outputs, then interpret the same result as a combination of columns.

In Module 11.2, a matrix product connected two grids. What if we have just one set of input values? The vector from Module 10.3 is a one-column grid, so the same multiplication rule turns it into one set of outputs. Each row states how to combine the inputs for one output, whether that output is a score or a new coordinate.

This is intermediate linear algebra. Learn matrix products in OpenStax, then treat the vector as a one-column matrix.

A basic idea: one row, one output

If AA has shape m×nm\times n and xx is an n×1n\times1 vector, then AxAx is an m×1m\times1 vector. Row ii of AA produces output yi=∑j=1naijxjy_i=\sum_{j=1}^{n}a_{ij}x_j.

For example,

[21−13][42]=[2(4)+1(2)−1(4)+3(2)]=[102].\begin{bmatrix}2&1\\-1&3\end{bmatrix} \begin{bmatrix}4\\2\end{bmatrix} =\begin{bmatrix}2(4)+1(2)\\-1(4)+3(2)\end{bmatrix} =\begin{bmatrix}10\\2\end{bmatrix}.

Two rows of a two-by-two matrix each combine the same two input values to produce one output value.Two rows of a two-by-two matrix each combine the same two input values to produce one output value.
Every output uses the full input vector and one matrix row.

A quick tour of properties

The same result is a combination of columns: if A=[a1 ⋯ an]A=[a_1\ \cdots\ a_n], then Ax=x1a1+⋯+xnanAx=x_1a_1+\cdots+x_na_n. Here each input xjx_j scales one whole column, and the scaled columns add to the output. This is the same arithmetic seen from the input side rather than one output row at a time. Dimensions tell you whether the product is defined: a vector with the wrong number of entries cannot be multiplied by AA. Matrix–vector multiplication is linear: A(u+v)=Au+AvA(u+v)=Au+Av and A(cu)=cAuA(cu)=cAu. Combining inputs before applying AA gives the same result as combining their outputs afterward.

Application 1: weighted scores

Two candidates have feature vectors x=(3,4)x=(3,4) and z=(5,1)z=(5,1). Score one uses weights (2,1)(2,1) and score two uses (1,3)(1,3). Stacking the weights as rows gives

A=[2113].A=\begin{bmatrix}2&1\\1&3\end{bmatrix}.

Then Ax=(10,15)Ax=(10,15) and Az=(11,8)Az=(11,8). Candidate zz leads on the first score; xx leads on the second. Each row states how that score weights the features.

Application 2: a coordinate transformation

Let T=[0110]T=\begin{bmatrix}0&1\\1&0\end{bmatrix}. For v=(2,3)v=(2,3),

Tv=[0⋅2+1⋅31⋅2+0⋅3]=[32].Tv=\begin{bmatrix}0\cdot2+1\cdot3\\1\cdot2+0\cdot3\end{bmatrix}=\begin{bmatrix}3\\2\end{bmatrix}.

The matrix swaps the coordinates: it reflects every point in the line y=xy=x. This is a geometric transformation rather than a score, but it uses the same row-by-vector arithmetic.

Resources

SourceTitleWhy read it
OpenStaxMatrices and matrix operationsUse matrix products with a one-column matrix.

Finished this module? Mark it done.

Comments

Stuck on something, spotted a mistake, or found a resource that helped you? Tell us below.

Loading comments