# xarray.DataArray.differentiate

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

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('741f599a-1845-406c-9cb6-f8a71896c9a3','bc808a76-04b6-4ab1-ab86-4d2044639aa4','18499c08-4517-4719-8848-0d15ef646581','../lite/tree/../notebooks/index.html?path=c028d34e_e64b_44a4_8dc7_5e9784362c27.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="18499c08-4517-4719-8848-0d15ef646581" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('741f599a-1845-406c-9cb6-f8a71896c9a3','18499c08-4517-4719-8848-0d15ef646581')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('741f599a-1845-406c-9cb6-f8a71896c9a3','18499c08-4517-4719-8848-0d15ef646581')">Open In Tab</button></div><div id="bc808a76-04b6-4ab1-ab86-4d2044639aa4" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
