title: How to use numpy to compute high-dimensional overlap integral
body: <p>Psi is stored as a ND numpy array on a spacial grid (for example if N=2 Psi is a 2D array of complex values). What is the best way to use numpy to compute the following integral:</p>
  
  <p><a href="https://i.stack.imgur.com/X1Qm8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X1Qm8.png" alt="enter image description here"></a></p>
  
  <p>I assume it will be a combination of <code>np.tensordot</code> and <code>np.sum</code>, but I cannot find a way to do it without relying on some heavy loops (problematic for large N).</p>