Confusion on the dot product

In the lecture I am not able to understand that how can we dot product two column vectors.
I have seen this type of multiplication in multiple places in the course, sometimes Prof. NG uses a transpose but this time explicitly there is a dot product and I don’t understand how a dot product can be applied to two matrices/vectors of same dimension.

The answer simply is: just do it.

What you are interested in is the final expression 2 * 0.71 + 3 * 0.71, computed from the vector coordinates (note that this only holds if the coordinates are expressed in an orthonormal base, otherwise the result won’t be the dot product, but that’s just by the by)

We are are in a setting where you know that the vector come only as column vectors (or they may come only as row vectors), and you know what you want to compute, so there is no obstacle in computing it: sum over pairwise products.

If you are in the setting of matrix multiplication, you have to be a bit more careful as now objects come as column vectors, row vectors or matrices. In that setting you actually cannot multiply two column vectors (or two row vectors) because the rules of the game do not allow it. To get the same expression corresponding to the scalar product, you have to do “row x column” multiplication (and only in that order as “column x row” will yield a matrix). But that’s okay, it’s just another setting, just another set of rules.

1 Like

A dot product of two vectors is relatively simple. It’s the sum of the element-wise products of the two vectors.

The two vectors must by definition be the same length.

As to the shapes, that’s a different matter. Whether the two vectors are considered row or column vectors is an implementation detail of the specific language being used.

1 Like

Hello, @mohit19,

Here is how I understand them. First I have a clear boundary between the vector regime and the matrix regime.

Vector: vector, dot product
Matrix: row matrix, column matrix, matrix multiplication, transpose

The thing is, when you have a sequence of numbers, you may express them in the form of a vector (which falls in the vector regime), or in the form of a row matrix or a column matrix.

When you have two things: a and b, if they are vectors, then the legitimate operation is dot product. Conversely, if they are dot-producted, then they are vectors.

Similarly, if they are matrices, then the operation is matrix multiplication, and transpose is used whenever needed to make the multiplication valid. Again, if they are matrix-multiplied, they are matrices.

Below is an example:

If we go serious, the left hand side (LHS) gives us a scalar, but the RHS a 1 x 1 matrix. I often see people said it is by a natural bijection that we can put an equal side to the two answers, so we have LHS = RHS. (I am not a maths expert so I am not the right person to explain this statement, but this result is seen everywhere).

Therefore, to me, the terminlogies of vector and matrix regime are never mixed but their result may be, as shown above, linked up.

Now, I will respond to what you wrote piece by piece:

Your screenshot showed a dot, so it is a dot product, so they are vectors.

If I were you, I would check again carefully if they are always dot products or sometimes not.

Then they are matrices.

Then they are vectors.

Cheers,
Raymond

1 Like

I recommend you to, after you clear our responses here, go through those places again and try to tell if they are in the forms of vector or matrices, because it is a good way to clear up those confusing impressions.

Remember that, a sequence of numbers can be written in either form: vector or matrix, but each form has its set of operations, so if the form is not explicitly specified, you may try to tell it from the operations.

Cheers,
Raymond

Thank you @rmwkwok , this clears majority of my doubt.
It seems that it was a vector operation.
Now i am a bit confused about Vectors. vs Matrices.. because I do not know which one is applied where and why :thinking:

Perhaps i need to go thru the course videos again to better understand which one is used where.

In a brief summary that applies to the MLS course:

Generally, the examples X are formed into a matrix, where each row contains the features for one example. So the size would be (m x n), where m is the number of examples, and n is the number of features.

Note that there is no universal standard for the shape of the X matrix. Sometimes it might be transposed to be size (n x m). It depends on the implementation.

Since there is one weight for each feature, the weights are a vector of size ‘n’.

Since there is one label for each example, the labels ‘y’ are a vector of size ‘m’.

Hello, @mohit19,

If you have a concrete example, please share that with us and we can discuss about it.

Cheers,
Raymond