NumPy roll moves entries around an array axis and brings values that cross the boundary back at the other end
Moving entries by a fixed number of positions can mean several different things. NumPy roll uses a circular arrangement: entries that pass one end return at the other. It does not fill newly exposed positions with zeros or discard the entries that cross the boundary. The output keeps the input shape.
Academia Master Trader presents this explanation in English for readers in Papua New Guinea. The examples describe numerical arrays only. They are not prices, trading signals or financial results. A clear account of the shift, the axis and the boundary behaviour makes this operation easier to read.
Begin with a short circular shift
Let a be [0,1,2,3,4]. The expression np.roll(a,2) produces [3,4,0,1,2]. Each entry moves two positions in the positive direction, and the final two entries reappear at the beginning.
There are still five values. Nothing is added to fill an empty space, because the movement wraps around the boundary. The order within the wrapped group remains three followed by four, then the remaining sequence continues from zero.

The result is not [0,0,0,1,2], which would describe a different boundary rule. It is also not [2,1,0,4,3], because roll is not a reversal. A small complete result is often clearer than the phrase move the values.
A negative shift moves the other way
For the same a, np.roll(a,-2) produces [2,3,4,0,1]. The first two entries move around to the end. Positive and negative shifts describe opposite directions along the array axis.
The sign belongs to the positional shift, not to the values. The zero and one retain their values when they reappear at the end. Rolling an array does not negate its entries or calculate a numerical difference between neighbours.
Name the shift direction together with the chosen example. Phrases such as forwards and backwards can be read differently, while the actual input and output make the intended arrangement explicit.
The default flattens before shifting
Now let x have rows [0,1,2,3,4] and [5,6,7,8,9]. Its shape is (2,5). The expression np.roll(x,1) returns rows [9,0,1,2,3] and [4,5,6,7,8].
With no axis supplied, the function first uses the flattened array for the shift and then restores the original shape. Nine wraps to the beginning of the flattened sequence, and four moves into the first position of the second row.
The restored shape does not mean that each original row was shifted independently. The movement crossed a row boundary in the flattened arrangement. Explain that default explicitly when presenting a two-dimensional input.
Select the row axis
The expression np.roll(x,1,axis=0) produces rows [5,6,7,8,9] and [0,1,2,3,4]. Here the rows move as units along the first axis, with the bottom row returning at the top.
The entries within each row keep their order. The output still has shape (2,5), but the grouping differs from the result with no axis supplied. Both outputs preserve shape, so shape alone does not identify the movement.
Because this example has only two rows, a shift of positive one and a shift of negative one along axis zero give the same row order. That equality follows from this particular two-position cycle; it is not a general rule for every array length.
Select the column axis
For the same x, np.roll(x,1,axis=1) produces rows [4,0,1,2,3] and [9,5,6,7,8]. Each row wraps independently along the column axis.
Compare this with the default result. Under the explicit column axis, four returns to the beginning of its own row and nine returns to the beginning of its own row. Under the default flattened shift, nine moves to the start of the whole arrangement.
Reading one complete row makes this distinction concrete. State the axis before describing which entry appears first, because the same shift count can produce different outputs under different axis choices.
Multiple axes can have separate shifts
The reference supports a tuple of shift counts together with a tuple of axes of the same length. Each shift corresponds to the axis in the same tuple position. The order of that pairing should be written clearly.
For the two-row x, np.roll(x,(2,1),axis=(1,0)) produces rows [8,9,5,6,7] and [3,4,0,1,2]. The column axis receives a shift of two, and the row axis receives a shift of one.
An integer shift can also be used with a tuple of axes, applying that same count to each named axis. Distinguish a shared count from separate counts, rather than assuming that every multidimensional operation has only one direction.
Explain the boundary rule first
Continue learning with Academia Master Trader at academiamastertrader.com.br. Aprenda provides access to educational material. Identify the shift count, state whether the array is flattened or an axis is selected, and show where wrapped entries return. That keeps circular movement distinct from reversal, padding and removing values.