The numpy.trapz()
function in NumPy is used to perform integration along a given axis by using the composite trapezoidal rule.
numpy.trapz(y, x=None, dx=1.0, axis=- 1)
The numpy.trapz()
function takes the following parameter values:
y
: This is the input array to be integrated. This is a required parameter.x
: This is the given sample points that corresponds to the y
values. This is an optional parameter.dx
: This is the spacing provided between the sample points when x
is None. The default value is 1
. This is an optional parameter.axis
: This represents the angle along which the integration is done.import numpy as np# creating the input array to be integratedmyarray = np.array([1,2,3])# creating the sample pointsx = np.array([4, 6, 8])# implementing the numpy.trapz() functionintarray = np.trapz(myarray, x)print(intarray)
numpy
module.myarray
using the array()
function.x
containing the sample points using the array()
function.numpy.trapz()
function on the arrays and assign the result to a variable intarray
.intarray
.