One-dimensional linear interpolation.
JAX implementation of numpy.interp()
.
x (ArrayLike) – N-dimensional array of x coordinates at which to evaluate the interpolation.
xp (ArrayLike) – one-dimensional sorted array of points to be interpolated.
fp (ArrayLike) – array of shape xp.shape
containing the function values associated with xp
.
left (ArrayLike | str | None) – specify how to handle points x < xp[0]
. Default is to return fp[0]
. If left
is a scalar value, it will return this value. if left
is the string "extrapolate"
, then the value will be determined by linear extrapolation. left
is ignored if period
is specified.
right (ArrayLike | str | None) – specify how to handle points x > xp[-1]
. Default is to return fp[-1]
. If right
is a scalar value, it will return this value. if right
is the string "extrapolate"
, then the value will be determined by linear extrapolation. right
is ignored if period
is specified.
period (ArrayLike | None) – optionally specify the period for the x coordinates, for e.g. interpolation in angular space.
an array of shape x.shape
containing the interpolated function at values x
.
Examples
>>> xp = jnp.arange(10) >>> fp = 2 * xp >>> x = jnp.array([0.5, 2.0, 3.5]) >>> interp(x, xp, fp) Array([1., 4., 7.], dtype=float32)
Unless otherwise specified, extrapolation will be constant:
>>> x = jnp.array([-10., 10.]) >>> interp(x, xp, fp) Array([ 0., 18.], dtype=float32)
Use "extrapolate"
mode for linear extrapolation:
>>> interp(x, xp, fp, left='extrapolate', right='extrapolate') Array([-20., 20.], dtype=float32)
For periodic interpolation, specify the period
:
>>> xp = jnp.array([0, jnp.pi / 2, jnp.pi, 3 * jnp.pi / 2]) >>> fp = jnp.sin(xp) >>> x = 2 * jnp.pi # note: not in input array >>> jnp.interp(x, xp, fp, period=2 * jnp.pi) Array(0., dtype=float32)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4