Python program to reverse a Numpy array?

PythonNumpyServer Side ProgrammingProgramming

This is a simple program wherein we have to reverse a numpy array. We will use numpy.flip() function for the same.

Algorithm

Step 1: Import numpy.
Step 2: Define a numpy array using numpy.array().
Step 3: Reverse the array using numpy.flip() function.
Step 4: Print the array.

Example Code

import numpy as np

arr = np.array([10,20,30,40,50])
print("Original Array: \n", arr)

arr_reversed = np.flip(arr)
print("\nReversed Array: \n", arr_reversed)

Output

Original Array:
[10 20 30 40 50]

Reversed Array:
[50 40 30 20 10]
raja
Published on 16-Mar-2021 10:38:13
Advertisements