Difference Between Dot and Matmul in NumPy
The 𝐧𝐩.𝐦𝐚𝐭𝐦𝐮𝐥() and 𝐧𝐩.𝐝𝐨𝐭() methods produce the same output for 2D (and 1D) arrays. This makes many believe that they are the same and can be used interchangeably, but that is not true.
The 𝐧𝐩.𝐝𝐨𝐭() method revolves around individual vectors (or 1D arrays). Thus, it computes the dot product of ALL vector pairs in the two inputs.
The 𝐧𝐩.𝐦𝐚𝐭𝐦𝐮𝐥() method, as the name suggests, is meant for matrices. Thus, it computes the matrix multiplication of corresponding matrices in the two inputs.
Thanks for reading Daily Dose of Data Science! Subscribe for free to receive new posts and support my work.
Find the code for my tips here: GitHub.
I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.