# numpy.trapz() function | Python

`numpy.trapz()` function integrate along the given axis using the composite trapezoidal rule.

Syntax : numpy.trapz(y, x = None, dx = 1.0, axis = -1)

Parameters :
y : [array_like] Input array to integrate.
x : [array_like, optional] The sample points corresponding to the y values. If x is None, the sample points are assumed to be evenly spaced dx apart. The default is None.
dx : [scalar, optional] The spacing between sample points when x is None. The default is 1.
axis : [int, optional] The axis along which to integrate.

Return :
trapz: [float] Definite integral as approximated by trapezoidal rule.

Code #1 :

 `# Python program explaining ` `# numpy.trapz() function ` ` `  `# importing numpy as geek   ` `import` `numpy as geek ` ` `  `y ``=` `[``1``, ``2``, ``3``, ``4``] ` ` `  `gfg ``=` `geek.trapz( y ) ` ` `  `print` `(gfg) `

Output :

```7.5
```

Code #2 :

 `# Python program explaining ` `# numpy.trapz() function ` ` `  `# importing numpy as geek   ` `import` `numpy as geek ` ` `  `y ``=` `[``1``, ``2``, ``3``, ``4``] ` `x ``=` `[``5``, ``6``, ``7``, ``8``] ` ` `  `gfg ``=` `geek.trapz(y, x) ` ` `  `print` `(gfg) `

Output :

```7.5
```

Code #3 :

 `# Python program explaining ` `# numpy.trapz() function ` ` `  `# importing numpy as geek   ` `import` `numpy as geek ` ` `  `y ``=` `[``1``, ``2``, ``3``, ``4``] ` ` `  ` `  `gfg ``=` `geek.trapz(y, dx ``=` `2``) ` ` `  `print` `(gfg) `

Output :

```15.0
```

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.