Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K
JAX  documentation - Home

jax.numpy.interp

Contents

jax.numpy.interp#

jax.numpy.interp(x,xp,fp,left=None,right=None,period=None)[source]#

One-dimensional linear interpolation.

JAX implementation ofnumpy.interp().

Parameters:
  • 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 shapexp.shape containing the function values associated withxp.

  • left (ArrayLike |str |None) – specify how to handle pointsx<xp[0]. Default is to returnfp[0].Ifleft is a scalar value, it will return this value. ifleft is the string"extrapolate", then the value will be determined by linear extrapolation.left is ignored ifperiod is specified.

  • right (ArrayLike |str |None) – specify how to handle pointsx>xp[-1]. Default is to returnfp[-1].Ifright is a scalar value, it will return this value. ifright is the string"extrapolate", then the value will be determined by linear extrapolation.right is ignored ifperiod is specified.

  • period (ArrayLike |None) – optionally specify the period for thex coordinates, for e.g. interpolationin angular space.

Returns:

an array of shapex.shape containing the interpolated function at valuesx.

Return type:

Array

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 theperiod:

>>>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)
Contents

[8]ページ先頭

©2009-2025 Movatter.jp