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.
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.