A dot product computes the sum of the products of the elements. So the shape of the result will be different than either operand.

The * operator computes the element-wise products, but doesn’t include the sum. The shape of the result will be the same as the shape of the two operands.

If the equation you’re implementing has the sum of two things that are multiplied, then look at the desired output shape.

In a matrix multiplication between matrix A (of i rows) and matrix B (of k columns), there are i \times k dot products. I believe you know how to implement one dot product with a * b and np.sum, so if you want to implement a matrix multiplication through implementing all of the dot products, it will be very complicated.

appreciate all the quick replies! Looking at the dimensions make sense!

Hi @rmwkwok, I understand the first sentence. Is it possible to elaborate “so if you want to implement a matrix multiplication through implementing all of the dot products, it will be very complicated” ? Do you mean

“i x k” matrix multiplication at a large dataset is already complicated itself
or 2) after implemented, it will be hard to do np.sum?

Don’t just think, but write down how you would compute A \times B with element-wise multiplication * and np.sum (You will have to loop through the rows in A and the columns in B).

Compare what you have written down to just np.dot(A, B) or just A @ B, then you see how complicated it is in terms of the effort to code.