I have two numpy array (x,y)-
import numpy as np
import scipy
from scipy.integrate import simps
y=np.array([1,1,2,1,-2])
x=np.array([0,1,2,3,4])
The scipy interpolators (such as InterpolatedUnivariateSpline) have an integral
method. For example,
In [23]: from scipy.interpolate import InterpolatedUnivariateSpline
In [24]: x = np.array([0, 1, 2, 3, 4])
In [25]: y = np.array([1, 1, 2, 1, -2])
In [26]: f = InterpolatedUnivariateSpline(x, y, k=1) # k=1 gives linear interpolation
In [27]: f.integral(1.5, 2.2)
Out[27]: 1.2550000000000003