NumPy flip reverses array positions along selected axes while preserving shape
Reversing an array changes where its entries appear without sorting their numeric values. NumPy flip reverses the order along one or more selected axes and preserves the array shape. Academia Master Trader presents this English lesson for readers in Vietnam. Constructed examples distinguish a reversed vector, a matrix with reversed rows, and a matrix with reversed columns, while explaining why the returned view needs careful handling.
Reverse a vector in its existing order
After import numpy as np, define a = np.array([4,1,9,2]). The call np.flip(a) returns [2,9,1,4]. The final input entry becomes the first output entry, and the first becomes the last. All four entries are retained, so the shape remains (4,).
The output is not sorted from smallest to largest or largest to smallest. Nine stays ahead of one because their positions were reversed together with the rest of the sequence. Flip uses the supplied arrangement as its starting point. If the vector represents observations over time, reversing it also reverses their positional order; it does not change the observation dates themselves.

Axis zero reverses the row order
Define m = np.array([[1,4,7],[2,5,8]]). The call np.flip(m,axis=0) returns [[2,5,8],[1,4,7]]. The second row now appears first, while the entries within each row retain their original order. The matrix shape stays (2,3).
The values one, four and seven still belong to the same row as one another. The operation changes the row positions, not the column positions inside each row. Keep any corresponding row labels aligned with the same reversal if those labels are stored separately from the numeric matrix.
Axis one reverses entries across each row
The call np.flip(m,axis=1) returns [[7,4,1],[8,5,2]]. Each row remains in its original row position, but the columns appear in the opposite order. The first column becomes the last, and the last becomes the first. Shape (2,3) is preserved again.
For this matrix, axis=-1 refers to the last axis and gives the same result as axis one. A negative axis number is a way to name an axis from the end, not a request to negate the numeric entries. Values retain their signs unless another operation changes them.
The default reverses every axis
The call np.flip(m) returns [[8,5,2],[7,4,1]]. With no axis specified, flip reverses all axes. Here that means reversing both the row order and the column order. It is different from reversing only the rows or only the columns.
The explicit call np.flip(m,axis=(0,1)) gives the same result for this two dimensional matrix. Flip does not exchange the meanings of rows and columns as a transpose would. A two by three matrix stays two by three, even when all of its axes are reversed.
The result is a view of the source
The documentation describes the returned result as a view. With a normal NumPy array, that means the reversed arrangement can share its underlying data with the original rather than holding an independent set of values. The reversal itself does not assign new numbers into m, but later writes through the view can affect the source.
For example, set v = np.flip(m,axis=1). Writing v[0,0] = 99 also changes m[0,2] to ninety nine. Use an explicit copy when an independently editable result is required. Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the selected axes, preserved shape and whether later work will edit a shared view or a separate copy.