SciPy is an open-source library provided by Python dedicated to scientific computation. The scipy.integrate
is a sub-package that provides the functionality to solve several integration methods, including Ordinary Differential Equations (ODEs). The scipy.integrate.trapz
method in SciPy is used to compute a definite integral using a simple Gaussian quadrature of fixed order n.
scipy.integrate.fixed_quad(func, a, b, args=(), n=5)
y
: The input array that needs to be integrated. It should be a Python array-like object.
x
: The sample points corresponding to the values. It should be a Python array-like object. The default value is None
. If x
is not given, the sample points are assumed to be evenly spaced apart by dx
.
dx
: An optional scaler representing the spacing between sample points when x
is None. The default value is 1
.
axis
: The axis along which to integrate is an optional number.
**trapz**
: The computed definite integral as approximated by the trapezoidal rule. It is a float
.
from scipy import integrateimport numpy as npprint(integrate.trapz([0,1,2]))
We pass the array [0,1,2]
to the scipy.integrate.trapz
method, which integrates this array using the trapezoidal rule.