Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K
JAX  documentation - Home

jax.numpy.trapezoid

Contents

jax.numpy.trapezoid#

jax.numpy.trapezoid(y,x=None,dx=1.0,axis=-1)[source]#

Integrate along the given axis using the composite trapezoidal rule.

JAX implementation ofnumpy.trapezoid()

The trapezoidal rule approximates the integral under a curve by summing theareas of trapezoids formed between adjacent data points.

Parameters:
  • y (ArrayLike) – array of data to integrate.

  • x (ArrayLike |None) – optional array of sample points corresponding to they values. If notprovided,x defaults to equally spaced with spacing given bydx.

  • dx (ArrayLike) – The spacing between sample points whenx is None (default: 1.0).

  • axis (int) – The axis along which to integrate (default: -1)

Returns:

The definite integral approximated by the trapezoidal rule.

Return type:

Array

Examples

Integrate over a regular grid, with spacing 1.0:

>>>y=jnp.array([1,2,3,2,3,2,1])>>>jnp.trapezoid(y,dx=1.0)Array(13., dtype=float32)

Integrate over an irregular grid:

>>>x=jnp.array([0,2,5,7,10,15,20])>>>jnp.trapezoid(y,x)Array(43., dtype=float32)

Approximate\(\int_0^{2\pi} \sin^2(x)dx\), which equals\(\pi\):

>>>x=jnp.linspace(0,2*jnp.pi,1000)>>>y=jnp.sin(x)**2>>>result=jnp.trapezoid(y,x)>>>jnp.allclose(result,jnp.pi)Array(True, dtype=bool)
Contents

[8]ページ先頭

©2009-2025 Movatter.jp