What is this t here? why we are doing its dot product with X?

You have to work out what the dimensions are. Prof Ng has defined the weight vector w to be a column vector. It has n_x elements, where that is the number of features in each input vector. So the dimensions of w are n_x x 1. Then x is one input sample and it is also a column vector of dimension n_x x 1. So you can’t do the dot product without the transpose, because the “inner” dimensions need to agree:

n_x x 1 dot n_x x 1 does not work.

So if we transpose w, then w^T is a row vector with dimensions 1 x n_x. Now it works:

1 x n_x dotted with n_x x 1 gives us a 1 x 1 answer, which is equivalent to a scalar.

Note that you could also do the dot product in the other order:

n_x x 1 dotted with 1 x n_x, but that gives a result that is n_x x n_x and has nothing to do with what we are trying to achieve here. Here’s a thread which demonstrates why.

The higher level point here is that we are always doing is starting with a mathematical formula. Then we need to figure out how to express that with linear algebra operations. Then as the final step, we need to figure out to express those linear algebra operations in python.

3 Likes