MCPcopy Index your code
hub / github.com/pydata/xarray / diff

Method diff

xarray/core/dataarray.py:4990–5039  ·  view source on GitHub ↗

Calculate the n-th order discrete difference along given axis. Parameters ---------- dim : Hashable Dimension over which to calculate the finite difference. n : int, default: 1 The number of times values are differenced. label : {"uppe

(
        self,
        dim: Hashable,
        n: int = 1,
        *,
        label: Literal["upper", "lower"] = "upper",
    )

Source from the content-addressed store, hash-verified

4988 return title
4989
4990 def diff(
4991 self,
4992 dim: Hashable,
4993 n: int = 1,
4994 *,
4995 label: Literal["upper", "lower"] = "upper",
4996 ) -> Self:
4997 """Calculate the n-th order discrete difference along given axis.
4998
4999 Parameters
5000 ----------
5001 dim : Hashable
5002 Dimension over which to calculate the finite difference.
5003 n : int, default: 1
5004 The number of times values are differenced.
5005 label : {"upper", "lower"}, default: "upper"
5006 The new coordinate in dimension ``dim`` will have the
5007 values of either the minuend's or subtrahend's coordinate
5008 for values 'upper' and 'lower', respectively.
5009
5010 Returns
5011 -------
5012 difference : DataArray
5013 The n-th order finite difference of this object.
5014
5015 Notes
5016 -----
5017 `n` matches numpy's behavior and is different from pandas' first argument named
5018 `periods`.
5019
5020 Examples
5021 --------
5022 >>> arr = xr.DataArray([5, 5, 6, 6], [[1, 2, 3, 4]], ["x"])
5023 >>> arr.diff("x")
5024 <xarray.DataArray (x: 3)> Size: 24B
5025 array([0, 1, 0])
5026 Coordinates:
5027 * x (x) int64 24B 2 3 4
5028 >>> arr.diff("x", 2)
5029 <xarray.DataArray (x: 2)> Size: 16B
5030 array([ 1, -1])
5031 Coordinates:
5032 * x (x) int64 16B 3 4
5033
5034 See Also
5035 --------
5036 DataArray.differentiate
5037 """
5038 ds = self._to_temp_dataset().diff(n=n, dim=dim, label=label)
5039 return self._from_temp_dataset(ds)
5040
5041 def shift(
5042 self,

Callers 1

Calls 2

_to_temp_datasetMethod · 0.95
_from_temp_datasetMethod · 0.95

Tested by 1