larray.Array.shift

Array.shift(axis, n=1) Array[source]

Shift the cells of the array n-times to the right along axis.

Parameters
axisint, str or Axis

Axis for which we want to perform the shift.

nint, optional

Number of cells to shift. Defaults to 1.

Returns
Array

See also

Array.roll

cells which are pushed “outside of the axis” are reintroduced on the opposite side of the axis instead of being dropped.

Examples

>>> arr = ndtest('sex=M,F;year=2019..2021')
>>> arr
sex\year  2019  2020  2021
       M     0     1     2
       F     3     4     5
>>> arr.shift('year')
sex\year  2020  2021
       M     0     1
       F     3     4
>>> arr.shift('year', n=-1)
sex\year  2019  2020
       M     1     2
       F     4     5