Suppose I have: w = {1,0}. I want to apply the dot product of w to each element of the list of vectors x = {{1,2}, {3,4}, {4,5}} to get {1,3,4}. Simply doing w.x does not work. How do I do this?

  • 5
    $\begingroup$ try x.w and it works $\endgroup$ – J42161217 May 13 '19 at 0:29

As J42161217 already wrote in a comment, you may use x.w in this case.

Should you ever have to compute the entrywise Dot-products of two lists of vectors x and y of same size, you may use the undocumented function NDSolve`FEM`MapThreadDot:

n = 1000000;
x = RandomReal[{-1, 1}, {n, 2}];
y = RandomReal[{-1, 1}, {n, 2}];

a = MapThread[Dot, {x, y}]; // AbsoluteTiming // First
b = NDSolve`FEM`MapThreadDot[x, y]; // AbsoluteTiming // First

Max[Abs[a - b]]




Unfortunately, this works only for vectors of machine precision reals.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.