You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / flip

_ArrayFunctionDispatcher

numpy:flip

source: /numpy/lib/_function_base_impl.py :272

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_like

Input array.

axis : None or int or tuple of ints, optional

Axis 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_like

A view of m with 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

fliplr

Flip an array horizontally (axis=1).

flipud

Flip an array vertically (axis=0).

Aliases

  • numpy.flip