tf.keras.ops.trapezoid

Integrate along the given axis using the composite trapezoidal rule.

y Input tensor.
x Optional tensor specifying sample points corresponding to y. If None, spacing is assumed to be dx.
dx Spacing between sample points when x is None.
axis Axis along which to integrate. Default is the last axis.

The approximate integral of y along the given axis.

Example:

y = keras.ops.convert_to_tensor([[1, 2, 3], [4, 5, 6]])
keras.ops.trapezoid(y, axis=1)
array([ 4., 10.], dtype=float32)