MCPcopy Create free account
hub / github.com/numpy/numpy / flip

Function flip

numpy/lib/function_base.py:255–345  ·  view source on GitHub ↗

Reverse the order of elements in an array along the given axis. The shape of the array is preserved, but the elements are reordered. .. versionadded:: 1.12.0 Parameters ---------- m : array_like Input array. axis : None or int or tuple of ints, optional

(m, axis=None)

Source from the content-addressed store, hash-verified

253
254@array_function_dispatch(_flip_dispatcher)
255def flip(m, axis=None):
256 """
257 Reverse the order of elements in an array along the given axis.
258
259 The shape of the array is preserved, but the elements are reordered.
260
261 .. versionadded:: 1.12.0
262
263 Parameters
264 ----------
265 m : array_like
266 Input array.
267 axis : None or int or tuple of ints, optional
268 Axis or axes along which to flip over. The default,
269 axis=None, will flip over all of the axes of the input array.
270 If axis is negative it counts from the last to the first axis.
271
272 If axis is a tuple of ints, flipping is performed on all of the axes
273 specified in the tuple.
274
275 .. versionchanged:: 1.15.0
276 None and tuples of axes are supported
277
278 Returns
279 -------
280 out : array_like
281 A view of `m` with the entries of axis reversed. Since a view is
282 returned, this operation is done in constant time.
283
284 See Also
285 --------
286 flipud : Flip an array vertically (axis=0).
287 fliplr : Flip an array horizontally (axis=1).
288
289 Notes
290 -----
291 flip(m, 0) is equivalent to flipud(m).
292
293 flip(m, 1) is equivalent to fliplr(m).
294
295 flip(m, n) corresponds to ``m[...,::-1,...]`` with ``::-1`` at position n.
296
297 flip(m) corresponds to ``m[::-1,::-1,...,::-1]`` with ``::-1`` at all
298 positions.
299
300 flip(m, (0, 1)) corresponds to ``m[::-1,::-1,...]`` with ``::-1`` at
301 position 0 and position 1.
302
303 Examples
304 --------
305 >>> A = np.arange(8).reshape((2,2,2))
306 >>> A
307 array([[[0, 1],
308 [2, 3]],
309 [[4, 5],
310 [6, 7]]])
311 >>> np.flip(A, 0)
312 array([[[4, 5],

Callers 1

rot90Function · 0.70

Calls 1

asarrayFunction · 0.50

Tested by

no test coverage detected