title: How can I express this large number of computations without for loops?
body: <p>I work primarily in MATLAB but I think the answer should not be too hard to carry over from one language to another.</p>
  
  <p>I have a multi-dimensional array <code>X</code> with dimensions <code>[n, p, 3]</code>. 
  I would like to calculate the following multi-dimensional array.</p>
  
  <pre><code>T = zeros(p, p, p)
  for i = 1:p
  for j = 1:p
  for k = 1:p
  T(i, j, k) = sum(X(:, i, 1) .* X(:, j, 2) .* X(:, k, 3));
  end
  end
  end
  </code></pre>
  
  <p>The sum is of the elements of a length-<code>n</code> vector.  Any help is appreciated!</p>