# xarray.DataArray.differentiate

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

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('7efb0901-7225-47f5-bb38-13eb63b88b01','c6aa7d12-1b3d-4460-a4e0-6b74ccae7058','a0e1c09e-bae0-425a-b9c0-9f24442ca175','../lite/tree/../notebooks/index.html?path=4c51c1fe_0004_4f91_a39a_9200049bc106.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="a0e1c09e-bae0-425a-b9c0-9f24442ca175" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('7efb0901-7225-47f5-bb38-13eb63b88b01','a0e1c09e-bae0-425a-b9c0-9f24442ca175')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('7efb0901-7225-47f5-bb38-13eb63b88b01','a0e1c09e-bae0-425a-b9c0-9f24442ca175')">Open In Tab</button></div><div id="c6aa7d12-1b3d-4460-a4e0-6b74ccae7058" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
