In [ ]:
%matplotlib inline

import matplotlib.pyplot as plt

import scipy.integrate

Integrating functions, given callable object (scipy.integrate.quad)


In [ ]:
f = lambda x: np.power(x, 2)

result = scipy.integrate.quad(f, 0, 3)
result

The return value is a tuple, with the first element holding the estimated value of the integral and the second element holding an upper bound on the error.

Integrating functions, given fixed samples


In [ ]:
x = np.linspace(0., 3., 100)
y = f(x)

In [ ]:
plt.plot(x, y);

In case of arbitrary spaced samples, the two functions trapz and simps are available.


In [ ]:
result = scipy.integrate.simps(y, x)
result

In [ ]:
result = scipy.integrate.trapz(y, x)
result