tf.keras.ops.rot90

Rotate an array by 90 degrees in the plane specified by axes.

This function rotates an array counterclockwise by 90 degrees k times in the plane specified by axes. Supports arrays of two or more dimensions.

array Input array to rotate.
k Number of times the array is rotated by 90 degrees.
axes A tuple of two integers specifying the plane of rotation (defaults to (0, 1)).

Rotated array.

Examples:

import numpy as np
from keras import ops
m = np.array([[1, 2], [3, 4]])
rotated = ops.rot90(m)
rotated
array([[2, 4],
       [1, 3]])
m = np.arange(8).reshape((2, 2, 2))
rotated = ops.rot90(m, k=1, axes=(1, 2))
rotated
array([[[1, 3],
        [0, 2]],
       [[5, 7],
        [4, 6]]])