# xarray.DataArray.interp_like

#### DataArray.interp_like(other, method='linear', assume_sorted=False, kwargs=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L2552-L2687)

Interpolate this object onto the coordinates of another object,
filling out of range values with NaN.

* **Parameters:**
  * **other** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset) or [`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Object with an ‘indexes’ attribute giving a mapping from dimension
    names to a 1d array-like, which provides coordinates upon
    which to index the variables in this dataset. Missing values are skipped.
  * **method** (`{"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "quintic", "polynomial", "pchip", "barycentric", "krogh", "akima", "makima"}`) – Interpolation method to use (see descriptions above).
  * **assume_sorted** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If False, values of coordinates that are interpolated over can be
    in any order and they are sorted first. If True, interpolated
    coordinates are assumed to be an array of monotonically increasing
    values.
  * **kwargs** ([`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), *optional*) – Additional keyword arguments passed to the interpolant.
* **Returns:**
  **interpolated** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Another dataarray by interpolating this dataarray’s data along the
  coordinates of the other object.

### Notes

- scipy is required.
- If the dataarray has object-type coordinates, reindex is used for these
  : coordinates instead of the interpolation.
- When interpolating along multiple dimensions with methods linear and nearest,
  : the process attempts to decompose the interpolation into independent interpolations
    along one dimension at a time.
- The specific interpolation method and dimensionality determine which
  : interpolant is used:
    1. **Interpolation along one dimension of 1D data (\`method=’linear’\`)**
       : - Uses [`numpy.interp()`](https://numpy.org/doc/stable/reference/generated/numpy.interp.html#numpy.interp), unless fill_value=’extrapolate’ is provided via kwargs.
    2. **Interpolation along one dimension of N-dimensional data (N ≥ 1)**
       : - Methods {“linear”, “nearest”, “zero”, “slinear”, “quadratic”, “cubic”, “quintic”, “polynomial”}
           : use `scipy.interpolate.interp1d()`, unless conditions permit the use of [`numpy.interp()`](https://numpy.org/doc/stable/reference/generated/numpy.interp.html#numpy.interp)
             (as in the case of method=’linear’ for 1D data).
         - If method=’polynomial’, the order keyword argument must also be provided.
    3. **Special interpolants for interpolation along one dimension of N-dimensional data (N ≥ 1)**
       : - Depending on the method, the following interpolants from `scipy.interpolate` are used:
           : - “pchip”: [`scipy.interpolate.PchipInterpolator`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.PchipInterpolator.html#scipy.interpolate.PchipInterpolator)
             - “barycentric”: [`scipy.interpolate.BarycentricInterpolator`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.BarycentricInterpolator.html#scipy.interpolate.BarycentricInterpolator)
             - “krogh”: [`scipy.interpolate.KroghInterpolator`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.KroghInterpolator.html#scipy.interpolate.KroghInterpolator)
             - “akima” or “makima”: `scipy.interpolate.Akima1dInterpolator`
               : (makima is handled by passing the makima flag).
    4. **Interpolation along multiple dimensions of multi-dimensional data**
       : - Uses [`scipy.interpolate.interpn()`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interpn.html#scipy.interpolate.interpn) for methods {“linear”, “nearest”, “slinear”,
           : “cubic”, “quintic”, “pchip”}.

#### SEE ALSO
[`DataArray.interp()`](xarray.DataArray.interp.html.md#xarray.DataArray.interp), [`DataArray.reindex_like()`](xarray.DataArray.reindex_like.html.md#xarray.DataArray.reindex_like), [`scipy.interpolate`](https://docs.scipy.org/doc/scipy/reference/interpolate.html#module-scipy.interpolate)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e2f728b4-0806-4f99-96f3-f943f9436712','512387fb-43e6-4dce-b04f-ed574d7441bb','294a7a14-57b3-4d4a-8adb-23f75c6eeac6','../lite/tree/../notebooks/index.html?path=9ff500e6_a0e5_4372_82fe_5cbae01f5cf2.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> data = np.arange(12).reshape(4, 3)
>>> da1 = xr.DataArray(
...     data=data,
...     dims=["x", "y"],
...     coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]},
... )
>>> da1
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
Coordinates:
  * x        (x) int64 32B 10 20 30 40
  * y        (y) int64 24B 70 80 90
>>> da2 = xr.DataArray(
...     data=data,
...     dims=["x", "y"],
...     coords={"x": [10, 20, 29, 39], "y": [70, 80, 90]},
... )
>>> da2
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11]])
Coordinates:
  * x        (x) int64 32B 10 20 29 39
  * y        (y) int64 24B 70 80 90
```

Interpolate the values in the coordinates of the other DataArray with respect to the source’s values:

```pycon
>>> da2.interp_like(da1)
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[0. , 1. , 2. ],
       [3. , 4. , 5. ],
       [6.3, 7.3, 8.3],
       [nan, nan, nan]])
Coordinates:
  * x        (x) int64 32B 10 20 30 40
  * y        (y) int64 24B 70 80 90
```

Could also extrapolate missing values:

```pycon
>>> da2.interp_like(da1, kwargs={"fill_value": "extrapolate"})
<xarray.DataArray (x: 4, y: 3)> Size: 96B
array([[ 0. ,  1. ,  2. ],
       [ 3. ,  4. ,  5. ],
       [ 6.3,  7.3,  8.3],
       [ 9.3, 10.3, 11.3]])
Coordinates:
  * x        (x) int64 32B 10 20 30 40
  * y        (y) int64 24B 70 80 90
```

<div id="294a7a14-57b3-4d4a-8adb-23f75c6eeac6" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e2f728b4-0806-4f99-96f3-f943f9436712','294a7a14-57b3-4d4a-8adb-23f75c6eeac6')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e2f728b4-0806-4f99-96f3-f943f9436712','294a7a14-57b3-4d4a-8adb-23f75c6eeac6')">Open In Tab</button></div><div id="512387fb-43e6-4dce-b04f-ed574d7441bb" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
