bundles / numpy 2.4.4 / numpy / flip
_ArrayFunctionDispatcher
numpy:flip
Signature
def flip ( m , axis = None ) Summary
Reverse the order of elements in an array along the given axis.
Extended Summary
The shape of the array is preserved, but the elements are reordered.
Parameters
m: array_likeInput array.
axis: None or int or tuple of ints, optionalAxis or axes along which to flip over. The default, axis=None, will flip over all of the axes of the input array. If axis is negative it counts from the last to the first axis.
If axis is a tuple of ints, flipping is performed on all of the axes specified in the tuple.
Returns
out: array_likeA view of
mwith the entries of axis reversed. Since a view is returned, this operation is done in constant time.
Notes
flip(m, 0) is equivalent to flipud(m).
flip(m, 1) is equivalent to fliplr(m).
flip(m, n) corresponds to m[...,::-1,...] with ::-1 at position n.
flip(m) corresponds to m[::-1,::-1,...,::-1] with ::-1 at all positions.
flip(m, (0, 1)) corresponds to m[::-1,::-1,...] with ::-1 at position 0 and position 1.
Examples
import numpy as np A = np.arange(8).reshape((2,2,2))✓
A np.flip(A, 0) np.flip(A, 1) np.flip(A) np.flip(A, (0, 2))✗
rng = np.random.default_rng() A = rng.normal(size=(3,4,5))✓
np.all(np.flip(A,2) == A[:,:,::-1,...])
✗See also
Aliases
-
numpy.flip