numpy.flip() in Python (original) (raw)
Last Updated : 08 Mar, 2024
The numpy.flip() function reverses the order of array elements along the specified axis, preserving the shape of the array.
Syntax: numpy.flip(array, axis)
Parameters :
array : [array_like]Array to be input axis : [integer]axis along which array is reversed.
Returns :
reversed array with shape preserved
Python
import
numpy as geek
array
=
geek.arange(
8
).reshape((
2
,
2
,
2
))
print
(
"Original array : \n"
, array)
print
(
"Flipped array : \n"
, geek.flip(array,
0
))
Output :
Original array : [[[0 1] [2 3]]
[[4 5] [6 7]]]
Flipped array : [[[4, 5] [6, 7]]
[[0, 1] [2, 3]]]
Note :
These codes won’t run on online IDE’s. So please, run them on your systems to explore the working.
Similar Reads
- numpy.fliplr() in Python numpy.fliplr(array) : Flip array(entries in each column) in left-right direction, shape preserved Parameters : array : [array_like]Input array, we want to flip Return : Flipped array in left-right direction. # Python Program illustrating # numpy.fliplr() method import numpy as geek array = geek.aran 1 min read
- numpy.flipud() in Python The numpy.flipud() function flips the array(entries in each column) in up-down direction, shape preserved. Syntax: numpy.flipud(array) Parameters : array : [array_like]Input array, we want to flip Return : Flipped array in up-down direction. Python Code # Python Program illustrating # numpy.flipud() 1 min read
- numpy.all() in Python The numpy.all() function tests whether all array elements along the mentioned axis evaluate to True. Syntax: numpy.all(array, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters : array :[array_like]Input array or object whose elements, we need to test. axis : 3 min read
- numpy.isnan() in Python The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax : numpy.isnan(array [, out]) Parameters : array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed with 2 min read
- numpy.any() in Python The numpy.any() function tests whether any array elements along the mentioned axis evaluate to True. Syntax : numpy.any(a, axis = None, out = None, keepdims = class numpy._globals._NoValue at 0x40ba726c) Parameters : array :[array_like]Input array or object whose elements, we need to test. axis : [i 3 min read
- numpy.invert() in Python numpy.invert() function is used to Compute the bit-wise Inversion of an array element-wise. It computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. For signed integer inputs, the two’s complement is returned. In a two’s-complement system negative num 2 min read
- numpy.copysign() in Python numpy.copysign(arr1, arr2, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None) : This mathematical function helps user to change the sign of arr1 and arr2. Both arr1 or arr2 can be either list/sequence or a scalar value. If sequence, both must have same dimension; otherwise a 2 min read
- numpy.flatnonzero() in Python numpy.flatnonzero()function is used to Compute indices that are non-zero in the flattened version of arr. Syntax : numpy.flatnonzero(arr) Parameters : arr : [array_like] Input array. Return : ndarray Output array, containing the indices of the elements of arr.ravel() that are non-zero. Code #1 : Wor 1 min read
- numpy.roll() in Python The numpy.roll() function rolls array elements along the specified axis. Basically what happens is that elements of the input array are being shifted. If an element is being rolled first to the last position, it is rolled back to the first position. Syntax : numpy.roll(array, shift, axis = None) Par 2 min read
- numpy.take() in Python The numpy.take() function returns elements from array along the mentioned axis and indices. Syntax: numpy.take(array, indices, axis = None, out = None, mode ='raise') Parameters : array : array_like, input array indices : index of the values to be fetched axis : [int, optional] axis over which we ne 2 min read