NAME

rotate - rotate elements of an array along an axis

SYNOPSIS

arr.rotate(num)
arr.rotate(num, axis)

DESCRIPTION

The rotate() method rotates the elements of an array along the specified axis. The elements are shifted by num positions. Elements shifted off one end of the axis are wrapped around to the other end. This is similar to APL num arr and num ⌽[axis] arr.

A positive num rotates elements towards higher indices, while a negative num rotates towards lower indices.

The axis parameter is an axis specification. If omitted, it defaults to the last axis (-1).

RETURN VALUE

A new array of the same shape and type as arr, with its elements rotated.

ERRORS

TypeCheck if arr is not an array, or if num or axis is not an integer
ArgCheck if an incorrect number of arguments is given
RangeCheck if axis is not a valid axis of arr

EXAMPLE

    arr = 5->iterate()
    arr
0 1 2 3 4

    arr.rotate(1)
4 0 1 2 3

    arr.rotate(-1)
1 2 3 4 0

    a = [2, 3].iterate()
    a
0 1 2
3 4 5

    a.rotate(1, 0)
3 4 5
0 1 2

    a.rotate(1, 1)
2 0 1
5 3 4

SEE ALSO

axis
reverse