Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K
JAX  documentation - Home

jax.numpy.diff

Contents

jax.numpy.diff#

jax.numpy.diff(a,n=1,axis=-1,prepend=None,append=None)[source]#

Calculate n-th order difference between array elements along a given axis.

JAX implementation ofnumpy.diff().

The first order difference is computed bya[i+1]-a[i], and the n-th orderdifference is computedn times recursively.

Parameters:
  • a (ArrayLike) – input array. Must havea.ndim>=1.

  • n (int) – int, optional, default=1. Order of the difference. Specifies the numberof times the difference is computed. If n=0, no difference is computed andinput is returned as is.

  • axis (int) – int, optional, default=-1. Specifies the axis along which the differenceis computed. The difference is computed alongaxis-1 by default.

  • prepend (ArrayLike |None) – scalar or array, optional, default=None. Specifies the values to beprepended alongaxis before computing the difference.

  • append (ArrayLike |None) – scalar or array, optional, default=None. Specifies the values to beappended alongaxis before computing the difference.

Returns:

An array containing the n-th order difference between the elements ofa.

Return type:

Array

See also

Examples

jnp.diff computes the first order difference alongaxis, by default.

>>>a=jnp.array([[1,5,2,9],...[3,8,7,4]])>>>jnp.diff(a)Array([[ 4, -3,  7],       [ 5, -1, -3]], dtype=int32)

Whenn=2, second order difference is computed alongaxis.

>>>jnp.diff(a,n=2)Array([[-7, 10],       [-6, -2]], dtype=int32)

Whenprepend=2, it is prepended toa alongaxis before computingthe difference.

>>>jnp.diff(a,prepend=2)Array([[-1,  4, -3,  7],       [ 1,  5, -1, -3]], dtype=int32)

Whenappend=jnp.array([[3],[1]]), it is appended toa alongaxisbefore computing the difference.

>>>jnp.diff(a,append=jnp.array([[3],[1]]))Array([[ 4, -3,  7, -6],       [ 5, -1, -3, -3]], dtype=int32)
Contents

[8]ページ先頭

©2009-2025 Movatter.jp