4
$\begingroup$

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.

$\endgroup$
6
$\begingroup$

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];
$\endgroup$
  • $\begingroup$ Seems to be what I want :-) $\endgroup$ – Jolyon May 25 '13 at 4:51

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.