Qu

rot90

Builtin index · Core maths

result = rot90(A, k=1)

Input: A, k · Output: result

What it is

Rotates A (a Mat, or anything coercible to one) 90°×k counterclockwise; k is an optional scalar defaulting to 1, may be negative for clockwise rotation, and is taken mod 4. An r×c input becomes c×r after an odd number of quarter-turns, or stays r×c after an even number.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = rot90(A, k=1)
A MatRotates A (a Mat, or anything coercible to one) 90°×k counterclockwise.
k scalar (default 1)k is an optional scalar defaulting to 1, may be negative for clockwise rotation, and is taken mod 4.
result Mat
Returns a Mat.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

v = [1, 2, 3, 4]
print("flip(v) = {flip(v)}")            # [4, 3, 2, 1]


A = [1, 2; 3, 4]
print("fliplr(A) = {fliplr(A)}")        # reverses column order: [2, 1; 4, 3]

print("flipud(A) = {flipud(A)}")        # reverses row order:    [3, 4; 1, 2]

print("rot90(A) = {rot90(A)}")          # 90 deg counterclockwise: [2, 4; 1, 3]

print("rot90(A, -1) = {rot90(A, -1)}")  # negative k rotates clockwise instead

output
flip(v) = [4, 3, 2, 1]
fliplr(A) = [2, 1; 4, 3]
flipud(A) = [3, 4; 1, 2]
rot90(A) = [2, 4; 1, 3]
rot90(A, -1) = [3, 1; 4, 2]

from fundamentals

How it works

rot90(A, [k=1]) — rotates A 90 degrees counterclockwise, k times (MATLAB/NumPy convention; k may be negative for clockwise rotation, and is taken mod 4).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.