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().

  • 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.


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

See also



>>> 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