How to use flip() function to Reverse a Numpy array In Python

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]

Python | Reverse a numpy array

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

Similar Reads

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....

Using the list slicing method to reverse a Numpy array

...

Using flipud function 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....