NumPy rot90 turns an array in quarter rotations within a chosen pair of axes
A quarter turn rearranges positions across two axes. It does not multiply values by ninety or calculate an angle for every entry. NumPy rot90 expresses that rearrangement with a rotation count and a pair of axes. Academia Master Trader presents this English lesson for readers in Thailand, using a small constructed matrix to make each moved position and each resulting shape easy to follow.
Follow the first quarter turn
After import numpy as np, define m = np.array([[1,4,7],[2,5,8]]). This matrix has two rows and three columns, so its shape is (2,3). The call np.rot90(m) returns [[7,8],[4,5],[1,2]]. With the default axis pair and rotation count, the two dimensional arrangement turns counterclockwise by ninety degrees.
The final source column, containing seven and eight, becomes the first output row. The first source column, containing one and two, becomes the final output row. There are still six entries, but the resulting shape is (3,2). A quarter turn can change an array's shape without adding or removing entries.

Count quarter turns rather than degrees
The argument k counts ninety degree turns. The call np.rot90(m,k=2) returns [[8,5,2],[7,4,1]], which is a half turn of the original arrangement. Its shape is (2,3), the same as the input. The values have moved even though the shape has returned to the original pair of lengths.
The call np.rot90(m,k=4) restores the original arrangement after four quarter turns. Passing k=90 does not request a ninety degree turn. It requests ninety quarter turns. Keeping the unit of the argument explicit prevents a number that looks familiar from expressing a different operation.
Reverse the direction with a negative count
The call np.rot90(m,k=-1) returns [[2,1],[5,4],[8,7]]. For this default plane, a negative quarter turn goes clockwise. Its output also has shape (3,2), but its entries differ from the positive quarter turn.
Shape alone cannot identify the direction used. Compare a known corner or a complete row with the source when explaining the result. In this example, two moves from the lower left source corner to the upper left output corner under the clockwise turn.
Keep the axis order explicit
The default axis pair is (0,1). Reversing that pair reverses the direction: np.rot90(m,axes=(1,0)) gives the same arrangement as np.rot90(m,k=-1). Both calls make the clockwise quarter turn shown above.
The two axes must be different. For an array with more than two dimensions, the selected pair defines the plane of the turn. Name those dimensions before using the operation, because an axis number does not explain whether it represents rows, columns, layers or another recorded dimension.
A rotated view can share the original data
The documentation describes the result as a rotated view. With an ordinary NumPy array, that means the result can share underlying data with its source rather than hold a separate set of entries. The rearrangement itself does not replace the input values, but writing through the returned view can affect the original array.
Starting again from m, set r = np.rot90(m). Writing r[0,0] = 99 also changes m[0,2] to ninety nine. Use an explicit copy when independent editing is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the axis pair, quarter turn count and resulting shape alongside the rearranged entries.