thin

UnitsAwareDataArray.thin(indexers: Mapping[Any, int] | int | None = None, **indexers_kwargs: Any) Self

Return a new DataArray whose data is given by each n value along the specified dimension(s).

Examples

>>> x_arr = np.arange(0, 26)
>>> x_arr
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25])
>>> x = xr.DataArray(
...     np.reshape(x_arr, (2, 13)),
...     dims=("x", "y"),
...     coords={"x": [0, 1], "y": np.arange(0, 13)},
... )
>>> x
<xarray.DataArray (x: 2, y: 13)> Size: 208B
array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12],
       [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]])
Coordinates:
  * x        (x) int64 16B 0 1
  * y        (y) int64 104B 0 1 2 3 4 5 6 7 8 9 10 11 12
>>>
>>> x.thin(3)
<xarray.DataArray (x: 1, y: 5)> Size: 40B
array([[ 0,  3,  6,  9, 12]])
Coordinates:
  * x        (x) int64 8B 0
  * y        (y) int64 40B 0 3 6 9 12
>>> x.thin({"x": 2, "y": 5})
<xarray.DataArray (x: 1, y: 3)> Size: 24B
array([[ 0,  5, 10]])
Coordinates:
  * x        (x) int64 8B 0
  * y        (y) int64 24B 0 5 10

See also

Dataset.thin, DataArray.head, DataArray.tail