xarray.Dataset.diff¶
-
Dataset.diff(dim, n=1, label='upper')¶ Calculate the n-th order discrete difference along given axis.
- Parameters
dim (
str) – 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 dimensiondimwill 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 (
same type as caller) – The n-th order finite difference of this object.note::– n matches numpy’s behavior and is different from pandas’ first argument named periods.
Examples
>>> ds = xr.Dataset({"foo": ("x", [5, 5, 6, 6])}) >>> ds.diff("x") <xarray.Dataset> Dimensions: (x: 3) Dimensions without coordinates: x Data variables: foo (x) int64 0 1 0 >>> ds.diff("x", 2) <xarray.Dataset> Dimensions: (x: 2) Dimensions without coordinates: x Data variables: foo (x) int64 1 -1
See also