str2d.Str2D.roll

Str2D.roll(x: int, axis: int) Str2D[source]

Roll the data along an axis. Analogous and wrapper to np.roll.

Parameters:
  • x (int) – The number of positions to roll.

  • axis (int) – The axis to roll along.

Return type:

Str2D

Examples

Let’s create an instance of Str2D and assign it to the variable a.

from str2d import Str2D

a = Str2D('a b c d\ne f g\nh i\nj')

We can roll the data horizontally by passing the number of positions to roll and the axis equal to 1.

a.roll(1, axis=1)
da b c
 e f g
 h i
 j

We can roll the data vertically by passing the number of positions to roll and the axis equal to 0.

a.roll(1, axis=0)
j
a b c d
e f g
h i