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

hi
i,m not sure when i have to use ‘‘multiplication’’ and when i have to use ‘‘np.dot()’’

but i guess when we have x[i] * y[i] , actually i mean when we have to multiplication two arrays which it’s formula has ‘‘superscript [i]’’ :

we have to use ‘‘np.dot()’’ for the multiplication;

and in other cases which hasn’t any superscript in it’s formula :
we have to use ‘’*’’ for the multiplication

am i wrong or what?

1 Like

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