title: Double integral with function and sampled data Python
body: <p>I am looking for a way to perform double integration on sampled data using numpy trapz or a similar function from the scipy stack.</p>
  
  <p>In particular, I would like to calculate function:</p>
  
  <p><a href="https://i.stack.imgur.com/CH14E.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CH14E.gif" alt="Equation"></a></p>
  
  <p>where <code>f(x',y')</code> is the sampled array and <code>F(x, y)</code> is an array of the same dimension.</p>
  
  <p>This is my attempt, which gives incorrect results:</p>
  
  <pre><code>def integrate_2D(f, x, y):
      def integral(f, x, y, x0, y0):
          F_i = np.trapz(np.trapz(np.arcsinh(1/np.sqrt((x-x0+0.01)**2+(y-y0+0.01)**2)) * f, x), y)
          return F_i
      sigma = 1.0
      F = [[integral(f, x, y, x0, y0) for x0 in x] for y0 in y]
      return F
  
  xlin = np.linspace(0, 10, 100)
  ylin = np.linspace(0, 10, 100)
  X,Y = np.meshgrid(xlin, ylin)
  
  f = 1.0 * np.exp(-((X - 8.)**2 + (Y - 8)**2)/(8.0))
  f += 0.5 * np.exp(-((X - 1)**2 + (Y - 9)**2)/(10.0))
  
  F = integrate_2D(f, xlin, ylin)
  </code></pre>
  
  <p>The output array seems to be oriented towards the diagonal of the resulting grid, while it should rather return an array that looks like blurred input array.</p>