diff1

arrayfire.diff1(array: Array, /, axis: int = 0) Array

Computes the first-order differences of an ArrayFire array along a specified dimension.

The first-order difference is calculated as array[i+1] - array[i] along the specified axis.

Parameters

arrayArray

The input ArrayFire array to compute differences on.

axisint, optional, default: 0

The dimension along which the first-order differences are calculated. For a 2D array, axis=0 computes the difference between consecutive rows, while axis=1 computes the difference between consecutive columns.

Returns

Array

An ArrayFire array of first-order differences. The size of this array along the specified axis is one less than the input array, as differences are computed between consecutive elements.

Examples

>>> import arrayfire as af
>>> a = af.Array([1, 2, 4, 7, 11])
>>> af.diff1(a)
[4 1 1 1]
    1.0000
    2.0000
    3.0000
    4.0000

Note

  • The differences for a 2D array along axis=0 would be row-wise differences,

and along axis=1 would be column-wise differences.