NumPy rollaxis relocates one axis using a start boundary rather than a value shift
Older array-processing code may use NumPy rollaxis to change axis order. The operation relocates one axis while keeping the remaining axes in their relative order. Academia Master Trader presents this English lesson for readers in Guinea, using a constructed array to explain the start argument and distinguish axis relocation from rolling numerical entries.
The default brings the chosen axis to the front
After import numpy as np, define x = np.arange(24).reshape(2,3,4). Its shape is (2,3,4). The call front = np.rollaxis(x,2) produces shape (4,2,3).
The original axis two becomes the first axis. The original length-two and length-three axes keep their relative order behind it. All 24 numerical entries remain present.
For a concrete coordinate, x[1,2,3] equals 23. The corresponding entry in the relocated view is front[3,1,2], also 23. The coordinate components follow their axes to the new positions.
This is a structural change. It does not sort the entries or move each value a fixed number of positions within an axis.

The start argument needs careful interpretation
When start is less than or equal to the chosen axis, the selected axis moves to that start position. For example, np.rollaxis(x,2,1) produces shape (2,4,3).
When start is greater than the chosen axis, the selected axis moves before that boundary in the original axis order. For this three-dimensional input, np.rollaxis(x,0,3) produces shape (3,4,2).
The latter call moves the original first axis to the end. Start three identifies the boundary after the existing axes; it does not create an output axis numbered three.
Avoid reading start as an ordinary final destination in every case. Its boundary meaning explains why moving an earlier axis forward can produce a different final index from the numeric start value.
Rollaxis and roll answer different questions
Rollaxis changes axis order. NumPy roll, by contrast, shifts numerical entries along an axis and brings entries that pass one end back at the other end.
Those operations can have very different meanings even when a printed array looks similar. Record whether the task calls for rearranging coordinate directions or cycling values within a direction.
Axis relocation also differs from a general reshape. The existing axes keep their individual lengths and coordinate meanings as their positions change.
Prefer moveaxis for new code
NumPy continues to support rollaxis for backward compatibility, but its documentation recommends moveaxis. For this input, np.moveaxis(x,0,-1) gives the same axis arrangement as np.rollaxis(x,0,3).
Current NumPy returns a view from rollaxis. A different arrangement therefore does not imply separate editable storage. Make an explicit copy if later edits must remain independent of the source.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the selected axis, start boundary and final axis order when reading older rollaxis code.