🍾 Xarray is now 10 years old! πŸŽ‰

xarray.DataArray.roll

Contents

xarray.DataArray.roll#

DataArray.roll(shifts=None, roll_coords=False, **shifts_kwargs)[source]#

Roll this array by an offset along one or more dimensions.

Unlike shift, roll treats the given dimensions as periodic, so will not create any missing values to be filled.

Unlike shift, roll may rotate all variables, including coordinates if specified. The direction of rotation is consistent with numpy.roll().

Parameters:
  • shifts (mapping of Hashable to int, optional) – Integer offset to rotate each of the given dimensions. Positive offsets roll to the right; negative offsets roll to the left.

  • roll_coords (bool, default: False) – Indicates whether to roll the coordinates by the offset too.

  • **shifts_kwargs ({dim: offset, ...}, optional) – The keyword arguments form of shifts. One of shifts or shifts_kwargs must be provided.

Returns:

rolled (DataArray) – DataArray with the same attributes but rolled data and coordinates.

See also

shift

Examples

>>> arr = xr.DataArray([5, 6, 7], dims="x")
>>> arr.roll(x=1)
<xarray.DataArray (x: 3)> Size: 24B
array([7, 5, 6])
Dimensions without coordinates: x