fn
diff
→Tensordiff(input: Tensor)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.])