I'm applying an integration function using scipy.integrate
to two 2D arrays. Here's the example:
from scipy import integrate
import numpy as np
def integrate_lno2(top, bottom, peak_height, peak_width):
return integrate.quad(lambda x: np.exp(-np.power(x - peak_height, 2)/(2*np.power(peak_width, 2))), top, bottom)[0]
# change row and col to test speed
row = 100; col = 100; peak_height=300; peak_width=60
top = np.linspace(100, 200, row*col).reshape(row, col)
bottom = np.linspace(800, 900, row*col).reshape(row, col)
res = np.zeros((row, col))
for i in range(row):
for j in range(col):
res[i, j] = integrate_lno2(top[i, j], bottom[i, j], peak_height, peak_width)
If the shape of 2D arrays increase, the for loop can be slow. I have found the numba integrand example, however it doesn't accept the upper and lower limit.