title: R equivalent of Python's np.dot for 3D array
body: <p>I am translating some code from Python to R involving 3D matrices. Which is tricky as I know very little Python or matrix algebra. Anyhow in the Python code I have a matrix dot.product as follows: <code>np.dot(A, B)</code>. Matrix A has dimension (10, 4) and B is (2, 4, 2).  (These dimensions may vary but always will match on the second dimension). So np.dot has no problem with this as from the documentation:</p>
  
  <blockquote>
    <p>"For 2-D arrays it is equivalent to matrix multiplication, and for 1-D
    arrays to inner product of vectors (without complex conjugation). For
    N dimensions it is a sum product over the last axis of a and the
    second-to-last of b:"</p>
  </blockquote>
  
  <p>Therefore it multiplies along the second axis of A=4, and the middle axis of B=4 and outputs a (10,2,2) matrix. => No problem. However in R, <code>%*%</code> does not have this behaviour and throws a 'non-conformable array' error.</p>
  
  <p>Toy example in r:</p>
  
  <pre><code>A &lt;- matrix( rnorm(10*4), nrow=10, ncol=4)
  B &lt;- array( rnorm(2*4*2), c(2,4,2))
  A %*% B
  Error in A %*% B : non-conformable arrays
  </code></pre>
  
  <p>How can I resolve this to achieve the same calculation as <code>np.dot</code>?</p>