I've got a list manipulation optimization problem. Consider a two-dimensional nxm list list1, and a three-dimensional nxmxm list, list2. Is there a faster way of taking the following product?

Table[list1[[i]].list2[[i]].list1[[i]], {i, 1, length}]

I know that Table operators are notoriously slow, and this seems like there might be a built-in list-manipulation operator to accomplish the same thing, or something very similar.


1 Answer 1


This is a straightforward application of MapThread:

out = MapThread[Dot, {list1, list2, list1}]

You can also use Thread as in the following, but it displays a Dot::dotsh message (which can be silenced with Quiet)

out = Quiet@Thread[list1.list2.list1];
  • $\begingroup$ Seems to be what I want :-) $\endgroup$
    – Jolyon
    Commented May 25, 2013 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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