diff(input: Tensor, n: _int = 1, dim: _int = -1, prepend: Tensor | None = None, append: Tensor | None = None)Compute the n-th order finite difference along an axis.
The first-order difference is ; higher orders apply the operation recursively. Each application reduces the size of the chosen axis by one.
Parameters
inputTensorSource tensor.
Returns
TensorTensor with the differenced axis shorter by n elements.
Notes
First-order differences are widely used as a discrete approximation to the derivative on a unit-spaced grid.
Examples
>>> import lucid
>>> x = lucid.tensor([1.0, 3.0, 6.0, 10.0])
>>> lucid.diff(x)
Tensor([2., 3., 4.])