NumPy rot90 rotates an array by quarter turns in a plane defined by two different axes

Turning a matrix through a right angle changes the positions of its entries in a particular way. NumPy rot90 expresses that operation as a number of quarter turns within a plane defined by two axes. For a two-dimensional array with the default settings, one turn is counterclockwise.

Academia Master Trader presents this explanation in English for readers in Solomon Islands. The examples concern numerical arrays only. They are not prices, trading signals or financial results. Reading the selected plane, the turn count and the output arrangement together makes the operation clear.

Begin with a two-by-two matrix

Let m have rows [1,2] and [3,4]. The expression np.rot90(m) produces rows [2,4] and [1,3]. This is the reference's basic two-dimensional example, with the default turn count of one and axes (0,1).

Follow the value two. It begins at the upper right and ends at the upper left. Four begins at the lower right and ends at the upper right. These positions show the counterclockwise turn without relying on the function name alone.

Original diagram: the matrix with rows one two and three four rotates one quarter turn counterclockwise into rows two four and one three under the default NumPy rot90 settings.

The values remain one, two, three and four. Rotation does not calculate a new numerical value for any entry. It changes their arrangement according to the selected axes and the number of turns.

The turn count is not a degree value

The parameter k counts how many times the array is rotated by ninety degrees. The default is one. For the same m, np.rot90(m,2) returns rows [4,3] and [2,1], corresponding to two quarter turns.

Do not read k as a direct angle in degrees. A value of two means two right-angle turns, not two degrees. Naming the unit as quarter turns keeps the parameter's role separate from a general geometric angle.

A useful explanation writes the function call, states the turn count and then reads the full result. That sequence gives the reader a concrete arrangement to compare with the original matrix.

Reversing the axes reverses the direction

The reference defines the rotation direction from the first selected axis towards the second. With the default two-dimensional axes (0,1), the default turn is counterclockwise. Swapping their order to (1,0) reverses that direction.

For the same m, np.rot90(m,1,axes=(1,0)) produces rows [3,1] and [4,2]. The value three moves from the lower left to the upper left, making the clockwise arrangement visible.

The documentation also states that this reversed axis order with k equal to one is equivalent to keeping axes (0,1) and using k equal to negative one. The sign and the ordered axis pair both matter when explaining direction.

Two different axes define the plane

The input must have at least two dimensions. The axes parameter names two different axes, because those axes define the plane in which the rotation occurs. A single vector does not supply that two-axis plane on its own.

For an array with more than two dimensions, the selected pair still determines the plane. The function does not require every dimension to participate in the rotation. Specify the pair rather than describing the operation only as rotating the array.

The reference includes a three-dimensional example using axes (1,2). That selection rotates within the plane of the final two dimensions while retaining the other dimension as a separate part of the arrangement. A two-dimensional diagram should not be mistaken for a picture of every possible plane.

A rectangular matrix can change its shape

A square example hides a useful detail. Let r have rows [1,2,3] and [4,5,6], giving it shape (2,3). The expression np.rot90(r) produces rows [3,6], [2,5] and [1,4].

The output shape is (3,2). There are still six entries, but the row and column counts exchange places under this quarter turn. Preserving the number of entries is not the same as preserving the shape.

Read both dimensions before and after the operation. That makes rotation distinct from reversing the order of rows or columns, where a rectangular two-dimensional array can retain its original shape.

The documented result is a view

The reference describes the return value as a rotated view of the input. Do not call it an independent full copy merely because its printed layout differs from the original. Arrangement and storage independence are separate properties.

That distinction matters if a later step changes entries. A view should not automatically be treated as a separate snapshot. If independent storage is needed, describe that as an additional requirement rather than as something guaranteed by rotation itself.

For teaching, keep the claims precise: the operation rotates entry positions, the axes define a plane, k counts quarter turns and the documented result is a view. None of those properties implies a new measurement or new numerical observation.

Read direction and shape together

Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Name the ordered axes, state the number of quarter turns and compare the input and output shapes. Following one corner entry then makes the rotation easy to distinguish from reversal or a simple exchange of row and column labels.