Python program to reverse a Numpy array?


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]

Updated on: 16-Mar-2021

478 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements