5
votes

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"?

2
Why is a function named? Do you think there is an answer to that? the most likely thing is that you like it, the name of a function does not have to have any basis, it would be best if you write an email to the numpy developers asking them because they are the only ones who know the reason.eyllanesc
Each element in a matrix product is the dot product of the corresponding row and column from the inputsMad Physicist
np.dot does produce a scalar - when the inputs are 1d arrays. The conventional matrix multiplication is defined for 2d arrays. But what's the definition, and name, for 3d or mix of dimensions? There is a new name - np.matmul. And for even greater generality there's Einstein notation, np.einsum.hpaulj
for n and m dimensional arrays, or "tensors" N and M, N.dot(M) will have dimension (n + m - 2). (as the first dimension of N and last dimension of M will be summed over). For n = m = 1, the output is a 0-d tensor, or scalar, and this is called a "scalar product". For n = m = 2, the output is a 2-d tensor, or "matrix", and the operation is called "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."Daniel F
Also this is far from an opinion-based question, as the dot ("inner") product and dot notation is well-defined mathematically, and the asker seems to simply not know the complete definition.Daniel F

2 Answers

3
votes

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.

2
votes

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.