# xarray.DataArray.differentiate

#### DataArray.differentiate(coord, edge_order=1, datetime_unit=None)[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataarray.py#L5599-L5660)

Differentiate the array with the second order accurate central
differences.

#### NOTE
This feature is limited to simple cartesian geometry, i.e. coord
must be one dimensional.

* **Parameters:**
  * **coord** (`Hashable`) – The coordinate to be used to compute the gradient.
  * **edge_order** (`{1, 2}`, *default*: `1`) – N-th order accurate differences at the boundaries.
  * **datetime_unit** (`{"W", "D", "h", "m", "s", "ms", "us", "ns", "ps", "fs", "as", None}`, *optional*) – Unit to compute gradient. Only valid for datetime coordinate. “Y” and “M” are not available as
    datetime_unit.
* **Returns:**
  **differentiated** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray))

#### SEE ALSO
[`numpy.gradient`](https://numpy.org/doc/stable/reference/generated/numpy.gradient.html#numpy.gradient)
: corresponding numpy function

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('c3c07fa5-716b-42c0-8acd-0970f0548d73','e0342a68-35dd-403a-9cb5-4ab4567bf42c','40c767d9-2de5-4074-9973-7b421b921456','../lite/tree/../notebooks/index.html?path=d70a493d_eb52_4a68_8540_aa49f3105d0e.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(
...     np.arange(12).reshape(4, 3),
...     dims=["x", "y"],
...     coords={"x": [0, 0.1, 1.1, 1.2]},
... )
>>> da
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
Coordinates:
  * x        (x) float64 32B 0.0 0.1 1.1 1.2
Dimensions without coordinates: y
>>>
>>> da.differentiate("x")
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[30.        , 30.        , 30.        ],
       [27.54545455, 27.54545455, 27.54545455],
       [27.54545455, 27.54545455, 27.54545455],
       [30.        , 30.        , 30.        ]])
Coordinates:
  * x        (x) float64 32B 0.0 0.1 1.1 1.2
Dimensions without coordinates: y
```

<div id="40c767d9-2de5-4074-9973-7b421b921456" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('c3c07fa5-716b-42c0-8acd-0970f0548d73','40c767d9-2de5-4074-9973-7b421b921456')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('c3c07fa5-716b-42c0-8acd-0970f0548d73','40c767d9-2de5-4074-9973-7b421b921456')">Open In Tab</button></div><div id="e0342a68-35dd-403a-9cb5-4ab4567bf42c" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
