Clarification '' the difference between normal multiplication (x*y) and np.dot(x,y)

Sorry, but I don’t think there is any such simple rule involving superscripts. Everything we are doing here is translating mathematical formulas into code. So it all depends on understanding what the mathematical formulas say, right? Elementwise multiply between two objects requires that they be the same shape or “broadcastable” to the same shape and then it just does what you’d expect from the description: it gives you an output object of the same shape that has each element as the product of the corresponding elements of the two inputs. Dot product multiplication is another matter entirely. The number of columns of the first operand must equal to the number of rows of the second operand (which is normally more simply stated as “the inner dimensions must agree”) and then each element of the output object is the vector dot product of one row of the first operand with one column of the second operand.

In terms of the notation Prof Ng uses, there is one rule that should work: when he’s showing an expression that has vectors or matrices in it, he will always use “*” when he means elementwise multiply. If he just writes two vectors or matrices adjacent to each other with no operator, that means “real” matrix multiply (dot product style).

Here’s another thread which gives a longer and more complete version of the above answer.

3 Likes