Stephen
Stephen

Reputation: 8810

why is the Numpy matrix multiplication operation called "dot"?

I am a bit confused about the naming of the Numpy function dot: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.dot.html

It seems like this is what is used in Numpy to perform matrix multiplication. However the "dot product" is something different, it produces a single scalar from two vectors: https://en.wikipedia.org/wiki/Dot_product

Can somebody resolve these two uses of the term "dot"?

Upvotes: 7

Views: 991

Answers (2)

Daniel F
Daniel F

Reputation: 14399

The "dot" or "inner" product has an expanded definition in tensor algebra compared to linear algebra.

For n and m dimensional tensors N and M, N⋅M will have dimension (n + m - 2), as the "inner dimensions" (last dimension of N and first dimension of M) will be summed over after multiplication.

(as an aside, N.dot(M) actually sums over the last dimension of N and the second-last dimension of M, because . . . reasons. The actual tensor algebra "dot product" functionality is relegated to np.tensordot)

For n = m = 1 (i.e. both are 1-d tensors, or "vectors"), the output is a 0-d tensor, or "scalar", and this is equivalent to the "scalar" or "dot" product from linear algebra.

For n = m = 2 (i.e. both are 2-d tensors, or "matrices"), the output is a 2-d tensor, or "matrix", and the operation is eqivalent to "matrix multiplication".

And for n = 2, m = 1, the output is a 1d tensor, or "vector", and this is called (at least by my professors) "mapping."

Note that since the order of dimensions is relevent to the construction of the inner product,

N.dot(M) == M.dot(N)

is not generally True unless n = m = 1 - i.e. only in the case of the scalar product.

Upvotes: 2

wim
wim

Reputation: 362796

It is common to write multiplication using a centrally positioned dot:

A⋅B

The name almost certainly comes from this notation. There is actually a dedicated codepoint for it named DOT OPERATOR under the "Mathematical Operators" block of unicode: chr(0x22c5). The comments mention this as

...for denotation of multiplication

Now, regarding this comment:

However the "dot product" is something different, it produces a single scalar from two vectors

They are not altogether unrelated! In a 2-d matrix multiplication A⋅B, the element at position (i,j) in the result has come from a dot product of row i by column j.

Upvotes: 3

Related Questions