cf.Data.roll¶
-
Data.
roll
(axis, shift, inplace=False, i=False)[source]¶ Roll array elements along one or more axes.
Elements that roll beyond the last position are re-introduced at the first.
See also
- Parameters
- axis:
int
, ortuple
ofint
Axis or axes along which elements are shifted.
- Parameter example:
Roll the second axis:
axis=1
.- Parameter example:
Roll the last axis:
axis=-1
.- Parameter example:
Roll the first and last axes:
axis=(0, -1)
.
- shift:
int
, ortuple
ofint
The number of places by which elements are shifted. If a
tuple
, then axis must be a tuple of the same size, and each of the given axes is shifted by the corresponding number. If anint
while axis is atuple
ofint
, then the same value is used for all given axes.- inplace:
bool
, optional If True then do the operation in-place and return
None
.- i: deprecated at version 3.0.0
Use the inplace parameter instead.
- axis:
- Returns
Examples
>>> d = cf.Data([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) >>> print(d.roll(0, 2).array) [10 11 0 1 2 3 4 5 6 7 8 9] >>> print(d.roll(0, -2).array) [ 2 3 4 5 6 7 8 9 10 11 0 1]
>>> d2 = d.reshape(3, 4) >>> print(d2.array) [[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] >>> print(d2.roll(0, 1).array) [[ 8 9 10 11] [ 0 1 2 3] [ 4 5 6 7]] >>> print(d2.roll(0, -1).array) [[ 4 5 6 7] [ 8 9 10 11] [ 0 1 2 3]] >>> print(d2.roll(1, 1).array) [[ 3 0 1 2] [ 7 4 5 6] [11 8 9 10]] >>> print(d2.roll(1, -1).array) [[ 1 2 3 0] [ 5 6 7 4] [ 9 10 11 8]] >>> print(d2.roll((1, 0), (1, 1)).array) [[11 8 9 10] [ 3 0 1 2] [ 7 4 5 6]] >>> print(d2.roll((1, 0), (2, 1)).array) [[10 11 8 9] [ 2 3 0 1] [ 6 7 4 5]]