xarray.Dataset.thin#
- Dataset.thin(indexers=None, **indexers_kwargs)[source]#
Returns a new dataset with each array indexed along every n-th value for the specified dimension(s)
- Parameters:
indexers (
dict
orint
) – A dict with keys matching dimensions and integer values n or a single integer n applied over all dimensions. One of indexers or indexers_kwargs must be provided.**indexers_kwargs (
{dim: n, ...}
, optional) – The keyword arguments form ofindexers
. One of indexers or indexers_kwargs must be provided.
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_ds = xr.Dataset({"foo": x}) >>> x_ds <xarray.Dataset> Dimensions: (x: 2, y: 13) Coordinates: * x (x) int64 0 1 * y (y) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 Data variables: foo (x, y) int64 0 1 2 3 4 5 6 7 8 9 ... 16 17 18 19 20 21 22 23 24 25
>>> x_ds.thin(3) <xarray.Dataset> Dimensions: (x: 1, y: 5) Coordinates: * x (x) int64 0 * y (y) int64 0 3 6 9 12 Data variables: foo (x, y) int64 0 3 6 9 12 >>> x.thin({"x": 2, "y": 5}) <xarray.DataArray (x: 1, y: 3)> array([[ 0, 5, 10]]) Coordinates: * x (x) int64 0 * y (y) int64 0 5 10
See also