Python | Reverse a numpy array Last Updated : 16 Sep, 2022 Comments Improve Suggest changes Like Article Like Report As we know Numpy is a general-purpose array-processing package that provides a high-performance multidimensional array object, and tools for working with these arrays. Let's discuss how can we reverse a Numpy array. Using flip() function to Reverse a Numpy array The numpy.flip() function reverses the order of array elements along the specified axis, preserving the shape of the array. Python3 import numpy as np # initialising numpy array ini_array = np.array([1, 2, 3, 6, 4, 5]) # using shortcut method to reverse res = np.flip(ini_array) # printing result print("final array", str(res)) Output: final array [5 4 6 3 2 1]Using the list slicing method to reverse a Numpy array This method makes a copy of the list instead of sorting it in order. To accommodate all of the current components, making a clone requires additional room. More RAM is used up in this way. Here, we're utilizing Python's slicing method to invert our list. Python3 import numpy as np # initialising numpy array ini_array = np.array([1, 2, 3, 6, 4, 5]) # printing initial ini_array print("initial array", str(ini_array)) # printing type of ini_array print("type of ini_array", type(ini_array)) # using shortcut method to reverse res = ini_array[::-1] # printing result print("final array", str(res)) Output: initial array [1 2 3 6 4 5] type of ini_array <class 'numpy.ndarray'> final array [5 4 6 3 2 1]Using flipud function to Reverse a Numpy array The numpy.flipud() function flips the array(entries in each column) in up-down direction, shape preserved. Python3 import numpy as np # initialising numpy array ini_array = np.array([1, 2, 3, 6, 4, 5]) # printing initial ini_array print("initial array", str(ini_array)) # printing type of ini_array print("type of ini_array", type(ini_array)) # using flipud method to reverse res = np.flipud(ini_array) # printing result print("final array", str(res)) Output: initial array [1 2 3 6 4 5] type of ini_array <class 'numpy.ndarray'> final array [5 4 6 3 2 1] Comment More infoAdvertise with us Next Article Python | Reverse a numpy array garg_ak0109 Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-arrayManipulation Practice Tags : python Similar Reads Python | Numpy MaskedArray.__rrshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rrshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rrshift__ Retur 1 min read numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read Python | Numpy MaskedArray.__rshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rshift__ Return: 1 min read NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read Python | Numpy MaskedArray.__rlshift__ numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rlshift__ method we can get the elements that is right shifted by the value that is provided as a parameter. Syntax: numpy.MaskedArray.__rlshift__ Retur 1 min read numpy.reshape() in Python In Python, numpy.reshape() function is used to give a new shape to an existing NumPy array without changing its data. It is important for manipulating array structures in Python. Let's understand with an example:Pythonimport numpy as np # Creating a 1D NumPy array arr = np.array([1, 2, 3, 4, 5, 6]) 3 min read Numpy MaskedArray.reshape() function | Python numpy.MaskedArray.reshape() function is used to give a new shape to the masked array without changing its data.It returns a masked array containing the same data, but with a new shape. The result is a view on the original array; if this is not possible, a ValueError is raised. Syntax : numpy.ma.resh 3 min read numpy.ravel() in Python The numpy.ravel() functions returns contiguous flattened array(1D array with all the input-array elements and with the same type as it). A copy is made only if needed. Syntax : numpy.ravel(array, order = 'C')Parameters : array : [array_like]Input array. order : [C-contiguous, F-contiguous, A-contigu 3 min read Numpy MaskedArray.ravel() function | Python numpy.MaskedArray.ravel() function is used to return a 1D version of self mask array, as a view. Syntax : numpy.ma.ravel(self, order='C') Parameters: order : [âCâ, âFâ, âAâ, âKâ, optional] By default, âCâ index order is used. --> The elements of a are read using this index order. --> âCâ means to in 2 min read Python | Numpy numpy.ndarray.__rshift__() With the help of numpy.ndarray.__rshift__() method, we can get the elements that is right shifted by the value that is provided as a parameter in numpy.ndarray.__rshift__() method. Syntax: ndarray.__rshift__($self, value, /) Return: self>>value Example #1 : In this example we can see that ever 1 min read Like