Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Python | Numpy MaskedArray.__rshift__
Next article icon

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]


Next Article
Python | Numpy MaskedArray.__rshift__
author
garg_ak0109
Improve
Article Tags :
  • Python
  • Python numpy-arrayManipulation
  • Python numpy-program
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • numpy.array_repr() in Python
    numpy.array_repr()function is used to convert an array to a string. Syntax : numpy.array_repr(arr, max_line_width=None, precision=None, suppress_small=None) Parameters : arr : [array_like] Input array. max_line_width : [int, optional] The maximum number of columns the string should span. Newline cha
    2 min read
  • numpy.ndarray.view() in Python
    numpy.ndarray.view() helps to get a new view of array with the same data. Syntax: ndarray.view(dtype=None, type=None)Parameters: dtype : Data-type descriptor of the returned view, e.g., float32 or int16. The default, None, results in the view having the same data-type as a. type : Python type, optio
    3 min read
  • 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
  • Python Lists VS Numpy Arrays
    Here, we will understand the difference between Python List and Python Numpy array. What is a Numpy array?NumPy is the fundamental package for scientific computing in Python. Numpy arrays facilitate advanced mathematical and other types of operations on large numbers of data. Typically, such operati
    7 min read
  • numpy.array_str() in Python
    numpy.array_str()function is used to represent the data of an array as a string. The data in the array is returned as a single string. This function is similar to array_repr, the difference being that array_repr also returns information on the kind of array and its data type. Syntax : numpy.array_st
    2 min read
  • Python | Numpy MaskedArray.__rmod__
    numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rmod__ every element in masked array is operated on binary operator i.e mod(%). Remember we can use any type of values in an array and value for mod is
    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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences