Multiply a matrix by a feature vector
Preserve the order of coordinates and the signs of values. · 165 words
In applied AI, a feature vector records measurable inputs, and a matrix stores weights. Multiplying an m by n matrix A by an n by 1 feature vector x produces an m by 1 output y. Each output is a dot product, meaning a sum of matching products. For example, let A = [[2, 1], [0, 3]] and x = [4, 5]. Then Ax = [2*4 + 1*5, 0*4 + 3*5] = [13, 15]. The inner dimensions match because every row has one weight for every feature.
A dot product depends on paired positions, so changing the order of features would change the result. Consider a museum recommendation model with two inputs: artifact age and visit count. Its matrix is R = [[0.5, 0.2], [0.1, 0.7]], and a visitor has x = [40, 3]. The first recommendation score is 0.5*40 + 0.2*3 = 20.6. The second is 0.1*40 + 0.7*3 = 6.1. Thus Rx = [20.6, 6.1]. Each output row represents a separate task-specific score.
Check your recall
If A has shape (3, 2) and x has shape (2, 1), what is the shape of Ax, and how is its first entry computed?
Check your answer
Ax has shape (3, 1). Its first entry is the sum of the two products obtained by pairing entries of the first matrix row with corresponding entries of x.
Sources and credits
Original KeyTouch lesson. Background reading · Zhang et al. · Linear Algebra.