# 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('00e23702-04ce-48b9-9f26-b55a0c3b5f14','6eab77ed-fdb4-47e6-8c5d-2d22fd677ebd','053b391d-4709-4092-9ac6-c2fb9f358402','../lite/tree/../notebooks/index.html?path=fa10ba9b_d87c_4758_8cec_a13d14a563ea.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="053b391d-4709-4092-9ac6-c2fb9f358402" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('00e23702-04ce-48b9-9f26-b55a0c3b5f14','053b391d-4709-4092-9ac6-c2fb9f358402')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('00e23702-04ce-48b9-9f26-b55a0c3b5f14','053b391d-4709-4092-9ac6-c2fb9f358402')">Open In Tab</button></div><div id="6eab77ed-fdb4-47e6-8c5d-2d22fd677ebd" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
