GeeksforGeeks App
Open App
Browser
Continue

Python | Scipy integrate.cumtrapz() method

With the help of `scipy.integrate.cumtrapz()` method, we can get the cumulative integrated value of y(x) using composite trapezoidal rule by using `scipy.integrate.cumtrapz()` method.

Syntax : `scipy.integrate.cumtrapz()`
Return : Return the cumulative integrated value of y(x).

Example #1 :
In this example we can see that by using `scipy.integrate.cumtrapz()` method, we are able to get the cumulative integration of y(x) using trapezoidal rule by using this method.

 `# import numpy and scipy.integrate.cumtrapz``import` `numpy as np``from` `scipy ``import` `integrate`` ` `x ``=` `np.arange(``0``, ``10``)``y ``=` `np.arange(``0``, ``10``)``# using scipy.integrate.cumtrapz() method``gfg ``=` `integrate.cumtrapz(y, x)`` ` `print``(gfg)`

Output :

[0.5 2. 4.5 8. 12.5 18. 24.5 32. 40.5]

Example #2 :

 `# import numpy and scipy.integrate.cumtrapz``import` `numpy as np``from` `scipy ``import` `integrate`` ` `x ``=` `np.arange(``0``, ``10``)``y ``=` `np.power(x, ``2``)``# using scipy.integrate.cumtrapz() method``gfg ``=` `integrate.cumtrapz(y, x)`` ` `print``(gfg)`

Output :

[0.5 3. 9.5 22. 42.5 73. 115.5 172. 244.5]

My Personal Notes arrow_drop_up