<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/probability/blob/v0.25.0/tensorflow_probability/python/math/integration.py#L30-L90) |

Integrate y(x) on the specified axis using the trapezoidal rule.

    tfp.math.trapz(
        y, x=None, dx=None, axis=-1, name=None
    )

Computes ∫ y(x) dx ≈ Σ \[0.5 (y*k + y*{k+1}) \* (x_{k+1} - x_k)\]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `y` | Float `Tensor` of values to integrate. |
| `x` | Optional, Float `Tensor` of points corresponding to the y values. The shape of x should match that of y. If x is None, the sample points are assumed to be evenly spaced dx apart. |
| `dx` | Scalar float `Tensor`. The spacing between sample points when x is None. If neither x nor dx is provided then the default is dx = 1. |
| `axis` | Scalar integer `Tensor`. The axis along which to integrate. |
| `name` | Python `str` name prefixed to ops created by this function. Default value: `None`, uses name='trapz'. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Float `Tensor` integral approximated by trapezoidal rule. Has the shape of y but with the dimension associated with axis removed. ||

<br />