Why np.dot(x,y) work differently than video demonstrate?

Andrew shows this in the video (week 1 - Matrix multiplication).

First part I might get wrong:
The example left is np.dot([1,2],[3,4]) or np.dot([[1],[2]],[[3],[4]]) ?

If I understand it right, that mean I can “dot” two 2D matrix as shape(2,1). But after I tested some parts worked wrong.

Besides, he also says a●w is the same as a(transpose)●w in the screenshot I took at the top. But the way only work is as below.

Even can’t change order!

Does I misunderstand some part? Or the numpy’s dot is not same as the “dot” Andrew mean?

Andrew was using two 1D column vectors. The best we can do in numpy is to construct column matrices in 2D, so they are different.

Keep your vectors in 1D will work too, in other words, don’t reshape.

My suggestion is to stick to the use of it so we can use it without error.


1 Like

Thank you so much! I’m reading the document of numpy.dot you give.

Just wonder two things:


The expression way in video as
-------------[ - ]
[1 2]
which is 1D and 2D? Currently I only sure [[1],[2]] is 2D.
For as I understand the
--------------1 3
-------------[ — ]
--------------2 4
means [[1,3],[2,4]]


Is this “expression” or “drawing” way especially for ML area? Or this is common sense in math?

Apparently 1D.



Hmmm… Both.

Put it this way. In Maths, we have dot product (aka inner product) and matrix multiplication. The former is for vectors whereas the latter matrices. np.dot may have a confusing name because it means both - not just inner product but also matrix multiplication depending on what are given to it as laid out in the use of it.

In the video, when we say dot, we identify them as vectors and not matrices. When we say matrix multiply, even it looks like a column vector, we would better term it as a column matrix. Afterall, a column vector and a column matric look identical when presenting in a maths equation in a video, don’t they?

1 Like

After your reply, I re-watched the video carefully about the vector and metrics and finally got it!
Thank you so much!
Just want to check some details. In vector, is there a difference in
–[ - ]
[1 2]
Or is that just a different display way, not from column to row? (Because vectors have no concept of row and column unless put into 2D…“vector” right?)

By wiki,

In mathematics, the dot product or scalar product [note 1] is an algebraic operation that takes two equal-length sequences of numbers (usually coordinate vectors), and returns a single number.

It doesn’t care the orientation at all, but the thing here is, I am discussing vectors in the context of dot product. If you ask me, is there any other (non-matrix-involved) context when the orientation matters? That is the part I would suggest you to hold on until you get to ask a maths professional.

1 Like

I understand~ Thanks a ton! :blush: