Returns a new dataset with each array indexed along every `n`-th value for the specified dimension(s) Parameters ---------- indexers : dict or int A dict with keys matching dimensions and integer values `n` or a single integer `n` applied over
(
self,
indexers: Mapping[Any, int] | int | None = None,
**indexers_kwargs: Any,
)
| 3249 | return self.isel(indexers_slices) |
| 3250 | |
| 3251 | def thin( |
| 3252 | self, |
| 3253 | indexers: Mapping[Any, int] | int | None = None, |
| 3254 | **indexers_kwargs: Any, |
| 3255 | ) -> Self: |
| 3256 | """Returns a new dataset with each array indexed along every `n`-th |
| 3257 | value for the specified dimension(s) |
| 3258 | |
| 3259 | Parameters |
| 3260 | ---------- |
| 3261 | indexers : dict or int |
| 3262 | A dict with keys matching dimensions and integer values `n` |
| 3263 | or a single integer `n` applied over all dimensions. |
| 3264 | One of indexers or indexers_kwargs must be provided. |
| 3265 | **indexers_kwargs : {dim: n, ...}, optional |
| 3266 | The keyword arguments form of ``indexers``. |
| 3267 | One of indexers or indexers_kwargs must be provided. |
| 3268 | |
| 3269 | Examples |
| 3270 | -------- |
| 3271 | >>> x_arr = np.arange(0, 26) |
| 3272 | >>> x_arr |
| 3273 | array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, |
| 3274 | 17, 18, 19, 20, 21, 22, 23, 24, 25]) |
| 3275 | >>> x = xr.DataArray( |
| 3276 | ... np.reshape(x_arr, (2, 13)), |
| 3277 | ... dims=("x", "y"), |
| 3278 | ... coords={"x": [0, 1], "y": np.arange(0, 13)}, |
| 3279 | ... ) |
| 3280 | >>> x_ds = xr.Dataset({"foo": x}) |
| 3281 | >>> x_ds |
| 3282 | <xarray.Dataset> Size: 328B |
| 3283 | Dimensions: (x: 2, y: 13) |
| 3284 | Coordinates: |
| 3285 | * x (x) int64 16B 0 1 |
| 3286 | * y (y) int64 104B 0 1 2 3 4 5 6 7 8 9 10 11 12 |
| 3287 | Data variables: |
| 3288 | foo (x, y) int64 208B 0 1 2 3 4 5 6 7 8 ... 17 18 19 20 21 22 23 24 25 |
| 3289 | |
| 3290 | >>> x_ds.thin(3) |
| 3291 | <xarray.Dataset> Size: 88B |
| 3292 | Dimensions: (x: 1, y: 5) |
| 3293 | Coordinates: |
| 3294 | * x (x) int64 8B 0 |
| 3295 | * y (y) int64 40B 0 3 6 9 12 |
| 3296 | Data variables: |
| 3297 | foo (x, y) int64 40B 0 3 6 9 12 |
| 3298 | >>> x.thin({"x": 2, "y": 5}) |
| 3299 | <xarray.DataArray (x: 1, y: 3)> Size: 24B |
| 3300 | array([[ 0, 5, 10]]) |
| 3301 | Coordinates: |
| 3302 | * x (x) int64 8B 0 |
| 3303 | * y (y) int64 24B 0 5 10 |
| 3304 | |
| 3305 | See Also |
| 3306 | -------- |
| 3307 | Dataset.head |
| 3308 | Dataset.tail |