xarray.Dataset.diff

Dataset.diff(dim, n=1, label='upper')

Calculate the n-th order discrete difference along given axis.

Parameters
  • dim (str, optional) – Dimension over which to calculate the finite difference.

  • n (int, optional) – The number of times values are differenced.

  • label (str, optional) – The new coordinate in dimension dim will have the values of either the minuend’s or subtrahend’s coordinate for values ‘upper’ and ‘lower’, respectively. Other values are not supported.

Returns

difference – The n-th order finite difference of this object.

Return type

same type as caller

Examples

>>> ds = xr.Dataset({'foo': ('x', [5, 5, 6, 6])})
>>> ds.diff('x')
<xarray.Dataset>
Dimensions:  (x: 3)
Coordinates:
  * x        (x) int64 1 2 3
Data variables:
    foo      (x) int64 0 1 0
>>> ds.diff('x', 2)
<xarray.Dataset>
Dimensions:  (x: 2)
Coordinates:
* x        (x) int64 2 3
Data variables:
foo      (x) int64 1 -1