NumPy flip reverses entry order along selected axes while preserving array shape
Reversing an array changes positional order rather than numeric values. NumPy flip reverses entries along one or more selected axes, keeping the original shape. Academia Master Trader presents this English lesson for readers in Mauritania, using constructed arrays to explain row and column reversal, the default axis choice and the shared memory of a returned view.
Reversing a vector changes its positional order
After import numpy as np, define v = np.array([7,2,9,4]). The call np.flip(v) returns [4,9,2,7]. The final entry becomes the first, the next-to-final entry becomes the second and the same reversal continues through the sequence.
This is not sorting. The result is neither ascending nor descending because flip follows the original positions rather than comparing values. It also differs from a circular shift, which moves entries by a fixed offset and wraps them across a boundary.
The output still has four entries. Reversing the same axis twice restores the original order. The operation therefore changes arrangement without adding entries or reducing the sequence to a summary.

The selected axis determines which positions reverse
Define m = np.array([[1,2,3],[4,5,6]]). The call np.flip(m,axis=0) returns [[4,5,6],[1,2,3]]. Row positions reverse, but the order of entries within each row remains unchanged.
The call np.flip(m,axis=1) returns [[3,2,1],[6,5,4]]. Column positions reverse within each row, while the rows retain their original vertical order. Both outputs have shape (2,3).
A negative axis counts backwards from the final axis. For this two-dimensional matrix, axis negative one identifies the column axis, so np.flip(m,axis=-1) gives the same result as axis one. Stating the axis avoids confusing row reversal with column reversal.
Shape alone cannot identify a reversal. The matrix still has two rows and three columns after either operation, even though its entries occupy different positions. Compare coordinates and values alongside shape when explaining how a reversed result relates to its source.
Omitting axis reverses every axis
The call np.flip(m) returns [[6,5,4],[3,2,1]]. Both row and column positions reverse. Supplying the tuple explicitly, as np.flip(m,axis=(0,1)), produces the same arrangement for this matrix.
This default does not mean that only the final axis is reversed. It applies to all axes of the input. The distinction becomes especially useful with arrays containing more than two dimensions, where several positional directions can be reversed together.
The returned view can share changes with its source
For an existing NumPy array, flip returns a view rather than an independent copy. The reordered view still refers to the underlying array data. Assigning through that view can therefore change an entry in the source array.
When an independent result is needed, use np.flip(m,axis=1).copy(). The copy separates later edits to the result from the original array. Keep reversal and copying as distinct decisions: one controls order, while the other controls whether data storage is shared.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the axes and whether the result is a view before explaining or editing a reversed array.