# The Dot Operator vs Standard Matrix Multiplication

GROUPS:
 The Dot operator can do both dot products and matrix multiplication. As a result,it can multiply a matrix by a row vector as in M.v, even though that's not kosherin linear algebra. I wonder if the documentation should warn about that.
4 years ago
12 Replies
 Ilian Gachevski 1 Vote See 'Possible Issues' in the Dot documentation: Dot effectively treats vectors multiplied from the right as column vectors.
4 years ago
 I don't think what's said in Possible Issues is completely correctIn[1]:= {{1, 2}, {3, 4}}.{5, 6}Out[1]= {17, 39}In[2]:= {{1, 2}, {3, 4}}.{{5}, {6}}Out[2]= {{17}, {39}}since you can use dot to right mulitply a matrix by a column vector.
4 years ago
 Ilian Gachevski 1 Vote I think this is exactly why the 'Possible Issues' give an explicit illustration for the {1, 1} and {{1}, {1}} cases, thereby making the same point. Both results are certainly correct according to the formal tensor definition given in the Details section.
4 years ago
 Ilian, rather than putting this in "Possible Issues", I'd suggest putting it in the main description, explaining how Mathematica's treatment of a matrix as a list of lists enables returning a list of dot products, as a row vector, when mulitplying a matrix by a row vector.
4 years ago
 Ilian Gachevski 1 Vote Maybe it does need more explaining. Personally I am not entirely convinced, but in any case, there is a 'Give Feedback' button at the bottom of each web documentation page, which is an excellent way to send any feedback or suggestions about the documentation content.
4 years ago
 Terrence Honan 1 Vote It is somewhat missing the point to talk about how Dot fails as matrix multiplication.  The point of Dot is that it is a tensor operation and that it sometimes corresponds to matrix multiplication. In terms of tensor indices, Dot contracts the right-most index of the first entry with the left-most index of the second. Using Part for indices we have for a tensor of rank p+1 and a tensor of rank q+1 then Dot gives a tensor of rank p+q.(T.U)[[i1,i2,...,ip,j1,j2,...,jq]]=Sum[T[[i1, i2, ..., ip, k]] U[[k, j1, j2, ..., jq]], {k, 1, n}]It is typical in Mathematica to define functions that are as general as they can reasonably be; Dot is a tensor generalization of matrix multiplication.
4 years ago
 I'm not saying that Dot fails at matrix multiplication; I'm saying that it overachieves.  That's fine except that it could be confusing to students learning linear algebra.
4 years ago
 Szabolcs Horvát 1 Vote Mathematica was designed to work with tensors of arbitrary dimensions, not just 2-dimensional matrices.  Correspondingly, Dot[] does tensor contraction, not just matrix multiplication.  I find this implementation much more logical and consistent than what I see in rigidly matrix based systems like MATLAB, which don't even support vectors.On Mathematica.SE I regularly see people trying to use "row vectors" and "column vectors" and a lot of transposision and complex indexing to try to do simple tasks.  This is all unnecessary complication in Mathematica, which does support proper 1D vectors, as well as N-D tensors.  I believe most of these people come from MATLAB or MATLAB-inspired software which typically doesn't support vectors at all, only row and column matrices.When I studied linear algebra, we started with vectors, not "row vectors" and "column vectors", and I didn't find it confusing.  So it's not quite accurate to say that this is "not kosher".  There are different traditions of teaching this stuff.  One is not necessarily better than the other.
4 years ago
 Yes, so think of all the questions to Stack Exchange that could be eliminated by simply explaining in the documentation how Mathematica takes a more general approach to vectors than other software.  You don't want to discourage people who are trying to switch to Mathematica.  Perhaps I'm thinking of this from a marketing viewpoint.  I suppose that's one of the dangers of having a Ph.D. in Physics and an M.B.A.  However, given the recent push to increase Mathematica's presence in STEM, I think that my suggestion makes sense.