diff2
- arrayfire.diff2(array: Array, /, axis: int = 0) Array
Computes the second-order differences of an ArrayFire array along a specified dimension.
The second-order difference is calculated as array[i+2] - 2*array[i+1] + array[i] along the specified axis, which is analogous to the second derivative in continuous functions.
Parameters
- arrayArray
The input ArrayFire array to compute second-order differences on.
- axisint, optional, default: 0
The dimension along which the second-order differences are calculated. For a 2D array, axis=0 computes the difference between consecutive rows (down each column), while axis=1 computes the difference between consecutive columns (across each row).
Returns
- Array
An ArrayFire array of second-order differences. The size of this array along the specified axis is two less than the input array, as the operation effectively reduces the dimension size by two.
Examples
>>> import arrayfire as af >>> a = af.Array([1, 2, 4, 7, 11]) >>> af.diff2(a) [3 1 1 1] 1.0000 1.0000 1.0000
Note
The operation requires that the array has at least three elements along the specified axis to compute the second-order differences. For arrays with fewer than three elements along the axis, the result will be an empty array.