- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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]
Advertisements